【发布时间】:2013-10-23 08:57:01
【问题描述】:
这是代码...
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script>
var geocoder;
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
var address = "new delhi";
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var latitude = results[0].geometry.location.lat();
var longitude = results[0].geometry.location.lng();
alert(latitude);
alert(longitude);
map.setCenter(new GLatLng(latitude, longitude));
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
var latlng = new google.maps.LatLng(latitude, longitude);
var mapOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
}
});
google.maps.event.addDomListener(window, 'load', initialize);
}
</script>
【问题讨论】:
-
GLatLng是 Google Maps API v2,已弃用(由于很快停止工作)。使用google.maps.LatLng代替@Nikhil 的回答
标签: javascript google-maps google-maps-api-3