I'm drawing a polygon on the map of google, I got it, but how big it is was a very repetitive code that I would like to isolate in a .json, but I could not.
I tried to do something simple with Jquery loading the file and putting it in a variable and tried using GeoJSON from google, but it did not work either.
The direct code in .js works however I wanted to isolate.
Today it looks 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 jquery read a json and put the content in the variable RareRegiao?
I tried:
var vareaRegiao;
$.getJSON(Pontos.json, function (data) {
vareaRegiao = data;
}
I 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 the debug it does not load the values.
UPDATE: I tried this way:
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
]