我正在使用谷歌地圖API 3和谷歌地理編碼。問題是它沒有顯示標記和信息窗口我正在通過ajax調用數據並調用函數showAddress(elemId,address)其中elementId是div id將在哪裏呈現地圖。在這裏,所以如果你把它們用作谷歌地圖API 3標記未顯示
lat = results[0].geometry.location.Ya;
lng = results[0].geometry.location.Za;
代碼很可能打破了谷歌地圖
<script type="text/javascript">
//<![CDATA[
var geocoder;
var map;
var lat;
var lng;
function showAddress(elemId, address) {
geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': address}, function(results, status){
// console.log(results[0].geometry.location.YA);
lat = results[0].geometry.location.Ya;
lng = results[0].geometry.location.Za;
var mapOptions = {
zoom: 15,
center: new google.maps.LatLng(lat, lng),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById(elemId),
mapOptions)
$('a#full-'+elemId).attr('href','http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q='+lat+','+lng+'')
var marker
marker = "marker_"+elemId;
myLatlng = new google.maps.LatLng(lat,lng);
marker = new google.maps.Marker({
id:elemId,
position: myLatlng,
map: map
});
var infowindow = "infowindow"+elemId;
infowindow = new google.maps.InfoWindow({
content: 'Hello world'
});
infowindow.open(map, marker);
google.maps.event.trigger(map, 'resize');
});
}
</script>
另外要注意在拉里(geocodezip)回覆第一點和檢查,如果(狀態== google.maps.Geoco地址解析器返回的狀態值derStatus.OK)....,如文檔中的示例所示:https://google-developers.appspot.com/maps/documentation/javascript/examples/geocoding-simple – Marcelo 2012-08-04 13:33:24