function initialize() {
var geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': '111 8th Avenue, New York, NY'}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var point = new google.maps.LatLng( results[0].geometry.location.lat() + ", " +results[0].geometry.location.lng() );
//alert( results[0].geometry.location.lat() + ", " +results[0].geometry.location.lng() );
//var point = new google.maps.LatLng(40.7406578, -74.00208940000005);
setTimeout(function(){
var mapOptions = {
zoom: 11,
center: point
};
var map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
var marker = new google.maps.Marker({
position: point,
map: map,
title: "111 8th Avenue, New York, NY"
});
}, 1000);
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
我想通过添加'地址'来查看谷歌地图。我得到了lat&很久了,但没有任何表现。如果我手动添加lat&长..
var point = new google.maps.LatLng(40.7406578, -74.00208940000005);
答案 0 :(得分:1)
该行(你在里面创建一个字符串)
var point = new google.maps.LatLng( results[0].geometry.location.lat() + ", " +results[0].geometry.location.lng() );
必须是:
var point = new google.maps.LatLng( results[0].geometry.location.lat(), results[0].geometry.location.lng() );