{"stops" : [{"zoneId":"5522bdb1e4b047df5b5b7afa","coords"
:[[[49.25100320801442,28.541126489672024],
[49.25156346163994,28.542151093515713],
[49.25113626882619,28.542376399072964],
[49.25074759018555,28.541657567056973],
[49.25076509829823,28.54119622710641],
[49.25100320801442,28.541126489672024]]],"name":"Ватутина","description":""}
request.open('GET', 'zones.json');
request.onreadystatechange = function() {
if ((request.status === 200) &&
(request.readyState === 4)) {
info = JSON.parse(request.responseText);
console.log(info.stops[0].coords[0][0]);
function initialize_map( ) {
var latlng = new google.maps.LatLng(info.stops[0].coords[0][0]);
var myOptions = {
zoom: 18,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var polygonCoords = [
new google.maps.LatLng(49.25156346163994,28.542151093515713),
new google.maps.LatLng(49.25113626882619,28.542376399072964),
new google.maps.LatLng(49.25074759018555,28.541657567056973),
new google.maps.LatLng(49.25076509829823,28.54119622710641),
new google.maps.LatLng(49.25100320801442,28.541126489672024)
];
var polygon = new google.maps.Polygon({
path: polygonCoords,
strokeColor: "#5196DB",
strokeOpacity: 1,
strokeWeight: 2,
fillColor: "#8ab9e7",
fillOpacity: 0.5
});
polygon.setMap(map);
return map;
}
var json = {
"stops" : [{
"zoneId":"5522bdb1e4b047df5b5b7afa",
"coords":[[
[49.25100320801442,28.541126489672024],
[49.25156346163994,28.542151093515713],
[49.25113626882619,28.542376399072964],
[49.25074759018555,28.541657567056973],
[49.25076509829823,28.54119622710641],
[49.25100320801442,28.541126489672024]
]],
"name":"Ватутина",
"description":""
}]
};
var polygonCoords = [];
var coords = json.stops[0].coords[0],
length = coords.length,
point,
POSITION_X = 0,
POSITION_Y = 1;
for(var i = 0; i < length; i++){
point = coords[i];
console.log(point[POSITION_X],point[POSITION_Y]);
// new google.maps.LatLng(point[POSITION_X],point[POSITION_Y]);
}
function initialize_map( ) {
var latlng = new google.maps.LatLng(info.stops[0].coords[0][0]);
var myOptions = {
zoom: 18,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var polygonCoords = [];
// ниже, я сохранил ссылку на json в свойство json,
// но как видно из Вашего кода, он у Вас называется info
// по этому я закоментирую свою строчку и оставлю Вашу.
// var coords = info.stops[0].coords[0],
var coords = info.stops[0].coords[0],
length = coords.length,
point,
POSITION_X = 0,
POSITION_Y = 1;
for(var i = 0; i < length; i++){
point = coords[i];
polygonCoords.push(new google.maps.LatLng(point[POSITION_X],point[POSITION_Y]));
}
var polygon = new google.maps.Polygon({
path: polygonCoords,
strokeColor: "#5196DB",
strokeOpacity: 1,
strokeWeight: 2,
fillColor: "#8ab9e7",
fillOpacity: 0.5
});
polygon.setMap(map);
return map;
}