2011-01-28 83 views
1

目前我使用latlang指定位置:使用Google Maps API v3進行地理編碼?

<script type="text/javascript"> 
function initialize() { 
var myLatlng = new google.maps.LatLng(52.097303, 0.275820); 
var myOptions = { 
zoom: 15, 
center: myLatlng, 
mapTypeId: google.maps.MapTypeId.ROADMAP 
} 
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 

var contentString = '<div id="bubbleContent">'+'<img src="images/logo.png" alt="logo" width="200" height="35"/>' 
'</div>'; 

var infowindow = new google.maps.InfoWindow({ 
content: contentString, 
}); 
var marker = new google.maps.Marker({ 
    position: myLatlng, 
    map: map, 
}); 
infowindow.open(map,marker); 
} 
</script> 

如何使用地理編碼使用的地址呢?例如劍橋,英國

感謝

+0

這已經在這個線程得到回答:http://stackoverflow.com/questions/10213147/using-google-api-gclientgeocoder – Duncan 2013-02-11 01:01:41

回答

-3

var map; var geocoder; var address;

function initialize() { map = new GMap2(document.getElementById("map_canvas")); map.setCenter(new GLatLng(40.730885,-73.997383), 15); map.addControl(new GLargeMapControl); GEvent.addListener(map, "click", getAddress); geocoder = new GClientGeocoder(); }

function getAddress(overlay, latlng) { if (latlng != null) { address = latlng; geocoder.getLocations(latlng, showAddress); } }

function showAddress(response) { map.clearOverlays(); if (!response || response.Status.code != 200) { alert("Status Code:" + response.Status.code); } else { place = response.Placemark[0]; point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]); marker = new GMarker(point); map.addOverlay(marker); marker.openInfoWindowHtml( '>b<orig latlng:>/b<' + response.name + '>br/<' + '>b<latlng:>/b<' + place.Point.coordinates[1] + "," + place.Point.coordinates[0] + '>br<' + '>b<Status Code:>/b<' + response.Status.code + '>br<' + '>b<Status Request:>/b<' + response.Status.request + '>br<' + '>b<Address:>/b<' + place.address + '>br<' + '>b<Accuracy:>/b<' + place.AddressDetails.Accuracy + '>br>' + '>b>Country code:>/b< ' + place.AddressDetails.Country.CountryNameCode); } }

+0

的問題是如何使用Api v3的地理編碼,而不是Api v2。 – 2013-01-02 19:46:20

相關問題