我創建了谷歌地圖使用JSON和使用的數據庫PostgreSQL的顯示標記谷歌地圖API無法使用JSON(V3)
這是我的代碼
<script type="text/javascript">
var map;
var national = [{"lng":"-6.173319","city":"JAKARTA","lat":"106.818672"}];
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(-0.789275,113.921327),
zoom: 5,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var infoWindow = new google.maps.InfoWindow();
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
$.getJSON('json_city.json', function(data) {
$.each(data.national, function(index, item) {
var myLatlng = new google.maps.LatLng(item.lat, item.lng);
alert(myLatlng);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: "text "+item.city
});
});
});
// Initialize the map
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
緯度和長期使用的字符類型(文本) 。我的地圖可以顯示,但我的標記不能顯示。
你在你的'國家'變量中有一個錯字; 「lat」和「lng」向後(應該是「lat」:「-6.173319」,「lng」:「106.818672」)。 ([小提琴](http://jsfiddle.net/geocodezip/f3rwcdyd/)) – geocodezip
感謝您的更正@geocodezip –