-1
lon和lat發送正確,但仍然不顯示標記。谷歌地圖的經緯度範圍
$(function() {
var map;
var markers = new Array();
var mapOptions = {
center: new google.maps.LatLng(46.4750370, 7.2843),
zoom: 7,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map"), mapOptions);
function initialize() {
// var bounds = new google.maps.LatLngBounds();
google.maps.event.addListener(map, 'zoom_changed', onClickCallback); //listen to zoom event and call function to reload markers
google.maps.event.addListener(map, 'drag', onClickCallback); //listen to drag/pan event and call function to reload markers
google.maps.event.addListener(map, 'tilesloaded', function() {
onClickCallback(map);
});
}
function onClickCallback(map) {
var bounds = map.getBounds();
$.getJSON('http://skiweather.eu/gmap3/markers/index.php', {
swLat: bounds.getSouthWest().lat(),
swLon: bounds.getSouthWest().lng(),
neLat: bounds.getNorthEast().lat(),
neLon: bounds.getNorthEast().lng()
}, function (data) {
$.each(data.markers, function (i, marker) {
$('#map').gmap('addMarker', {
'position': new google.maps.LatLng(marker.latitude, marker.longitude),
'bounds': true
}).click(function() {
$('#map').gmap('openInfoWindow', {
'content': marker.content
}, this);
});
});
});
}
google.maps.event.addDomListener(window, 'load', initialize);
我該如何製作一個全局變量? – mark
而不是在你的初始化函數中創建'var map;',而不是在你的初始化函數內部創建'var map;' – duncan
好吧,我這樣做了,但標記是不可見的。我改變了上面的代碼。 – mark