不确定这里发生了什么。
我在谷歌地图上显示位置(固定)。
没有什么复杂的,它没有问题。
但是当其中一个引脚点击时,我想要一个信息框来显示json文档中的场地名称。
我在这里做错了什么?
$("[name='checkinmap']").click(function() {
$(function CheckinMap() {
$.when($.ajax({
type: "GET",
dataType: "json",
url: "longlat.json"
})).done( function initialize(data) {
var infowindow;
var infoWindow;
var MapData = data;
var center = new google.maps.LatLng(48.404840395764175, 2.6845264434814453);
var map = new google.maps.Map(document.getElementById('checkinmap'), {
zoom: 2,
center: center,
mapTypeId: google.maps.MapTypeId.ROADMAP,
maxZoom: 4
});
google.maps.event.addListener(map, 'click', function(e) {
geocoder.geocode(
{'latLng': e.latLng},
function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[0]) {
if (marker) {
marker.setPosition(e.latLng);
} else {
marker = new google.maps.Marker({
position: e.latLng,
map: map});
}
infowindow.setContent(results[0].formatted_address);
infowindow.open(map, marker);
} else {
document.getElementById('geocoding').innerHTML =
'No results found';
}
} else {
document.getElementById('geocoding').innerHTML =
'Geocoder failed due to: ' + status;
}
});
});
var markers = [];
for (var i = 0; i < MapData.users.length; i++) {
var location = MapData.users[i];
var latLng = new google.maps.LatLng(location.latitude,
location.longitude);
var marker = new google.maps.Marker({
position: latLng
});
markers.push(marker);
}
var markerCluster = new MarkerClusterer(map, markers);
});
});
});
JSON:
{ "users": [ { "venuename": "MTR Hong Kong Station ???", "latitude": "22.284681", "longitude": "114.158177" }, { "venuename": "B & Company", "latitude": "24.8047737147982", "longitude": "46.7225638054951" } ] }