2
I am drawing a Poligono on the google map, I managed, but as it is big it got a very repetitive code that I would like to isolate in one . json but could not.
I tried to do something simple with Jquery loading the file and putting it in a variable and tried with the Geojson google, but also did not work.
The direct code in . js works but wanted to isolate.
today is like this:
var vareaRegiao = [
{ lat: -23.211000, lng: -46.71100 },
{ lat: -23.204000, lng: -46.70700 },
{ lat: -23.205000, lng: -46.70300 },
{ lat: -23.209000, lng: -46.70400 },
{ lat: -23.207000, lng: -46.70000 },
{ lat: -23.209000, lng: -46.69200 },
{ lat: -23.206000, lng: -46.68700 },
{ lat: -23.213000, lng: -46.66800 },
{ lat: -23.206000, lng: -46.67000 },
{ lat: -23.196000, lng: -46.65900 },
{ lat: -23.190000, lng: -46.66200 },
{ lat: -23.169000, lng: -46.65400 },
{ lat: -23.165000, lng: -46.65400 },
{ lat: -23.163000, lng: -46.65400 },
{ lat: -23.155000, lng: -46.66400 },
{ lat: -23.129000, lng: -46.67200 },
// e mais 200 linhas parecidas...
];
var varea_atibaia_monta = new google.maps.Polygon({
paths: vareaRegiao,
strokeColor: '#FF0000',
strokeOpacity: 0.9,
strokeWeight: 2,
fillColor: '#FF0000',
fillOpacity: 0.04
});
varea_atibaia_monta.setMap(map);
//fim area atibaia
How do I make jquery read a json and put the content into the variable vareaRegiao ?
tried:
var vareaRegiao;
$.getJSON(Pontos.json, function (data) {
vareaRegiao = data;
}
tried:
var vareaRegiao;
$.ajax({
type: "GET",
url: "/projto/Pontos.json,
dataType: "json",
success: function (data) {
vareaRegiao = data;
});
Most of the time it does not give error, but in debug it does not load the values.
UPDATE: I tried so:
var vareaRegiao;
$.ajax({
type: "GET",
url: "/scripts/coi/bordas.json",
dataType: "json",
success: function (data) {
console.log(data);
vareaRegiao = data;
inicia_tempo_real(vareaRegiao);
}
});
function inicia_tempo_real(vareaRegiao) {
mapOptions = {
center: new google.maps.LatLng(-23.120520, -46.546923),
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
infoWindow = new google.maps.InfoWindow();
map = new google.maps.Map($('#map_canvas')[0], mapOptions);
//area
var varea_atibaia_monta = new google.maps.Polygon({
paths: vareaRegiao,
strokeColor: '#FF0000',
strokeOpacity: 0.9,
strokeWeight: 2,
fillColor: '#FF0000',
fillOpacity: 0.04
});
varea_atibaia_monta.setMap(map);
//fim area
}
My JSON:
[
{ "lat": -23.211000, "lng": -46.71100 },
{ "lat": -23.204000, "lng": -46.70700 },
{ "lat": -23.205000, "lng": -46.70300 },
{ "lat": -23.209000, "lng": -46.70400 },
{ "lat": -23.207000, "lng": -46.70000 },
{ "lat": -23.209000, "lng": -46.69200 },
{ "lat": -23.206000, "lng": -46.68700 },
{ "lat": -23.213000, "lng": -46.66800 },
{ "lat": -23.206000, "lng": -46.67000 },
{ "lat": -23.196000, "lng": -46.65900 }//removi algumas linhas
]
I think the calling of the function that generates the map should be in success ajax. Remember that
vareaRegiao = data;
will not happen when the page loads, but rather when the ajax script returns something from outside– Miguel