我的代码:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script type="text/javascript" src="jquery.ui.map.full.min.js"></script>
<script>
function initialize() {
$('#map_canvas').gmap().bind('init', function() {
// This URL won't work on your localhost, so you need to change it
// see http://en.wikipedia.org/wiki/Same_origin_policy
$.getJSON( 'demo.json', function(data) {
$.each( data.markers, function(i, marker) {
$('#map_canvas').gmap('addMarker', {
'position': new google.maps.getLatLng(marker.town),
'bounds': true
}).click(function() {
$('#map_canvas').gmap('openInfoWindow', { 'content': marker.content }, this);
});
});
});
});
}
</script>
为什么 google.maps.getLatLng 不起作用?
更新:
$('#map_canvas').gmap('addMarker', { geocoder = new google.maps.Geocoder(); 'position': new google.maps.LatLng(geocoder.getLatLng(marker.town)), 'bounds': true })
如何根据城镇名称找到纬度和经度?我刚刚尝试了以上没有结果。