Google지도에 다각형을 표시하고 싶습니다.jQuery 및 Google지도 - 이상한 동작
- 는 JSON 파일에서 좌표 읽기 (버전 1)
- 변수에서 좌표 읽기 (버전 2)
불행하게도 유일한 버전 2 :
나는 두 가지 일을 수행 한 공장. paths: paths2
으로 설정하면 볼 수있는 일반지도 만 있습니다. paths: paths
을 사용하면 모든 것이 잘 동작합니다.
나는 '경로'와 '경로 2'가 어떻게 다른지 확인했지만 파이어 버그를 사용했지만 차이점이없는 것으로 보입니다. 이 JSON 파일을받지 못하고있다처럼
//Triangle
var bermudaTriangle;
//Create Map
var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);
//Version 1 (Load from JSON-file)
var paths2 = [];
var geojson2 = $.getJSON('./bermuda.json',function(data){
var foo = data.coordinates;
$.each(data.coordinates, function (i, n) {
var ll = new google.maps.LatLng(n[0], n[1]);
paths2.push(ll);
});
});
//Version 2 (Load from Variabel)
var paths = [];
var geojson = {"coordinates":[[25,-80],[18,-66],[32,-64],[25,-85]]};
$.each(geojson.coordinates, function (i, n) {
var ll = new google.maps.LatLng(n[0], n[1]);
paths.push(ll);
});
//Checkpoint for debugging (The variables are the same!!)
paths;
paths2;
bermudaTriangle = new google.maps.Polygon({
paths: paths,
strokeColor: "#FF0000",
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: "#FF0000",
fillOpacity: 0.35
});
bermudaTriangle.setMap(map);
함수'$ .getJSON ('./bermuda.json', function (data) {'? 그냥'path2'를 테스트하기위한 것입니다. ... – Littm