2013-07-27 124 views
0

我正在編寫一個腳本,允許您根據鼠標點擊的位置放置標記。我明白了。然而,當我通過反向地理編碼lat和lng時,似乎無法讓infowindow彈出。有人能幫助我嗎?謝謝!信息窗口未顯示反向地理編碼地址Google地圖V3

這裏是我的代碼:

var geocoder; 

function initialize() 
{ 

    geocoder = new google.maps.Geocoder(); 
    var event = google.maps.event.addListener; 

    // intializing and creating the map. 
    var mapOptions = { 
    zoom: 4, 
    center: new google.maps.LatLng(-25.363882, 131.044922), 
    mapTypeId: google.maps.MapTypeId.TERRAIN 
    }; 

    var map = new google.maps.Map(document.getElementById('map'), 
     mapOptions); 

    event(map,'click',function(e){ 
    var marker = placeMarker_and_attachMessage(e.latLng,map,count); 
    }); 

} // end of initalize. 

/* place down marker based on where you click the mouse over a certain area on the map. 
    An infowindow should appear with the location of your marker. 
*/ 

function placeMarker_and_attachMessage(position,map,num) 
{ 
    var event = google.maps.event.addListener; 

    var marker = new google.maps.Marker({ 
     position: position, 
     map: map 
    }); 

     var infowindow = new google.maps.InfoWindow({ 
      content: info_text(position) 
     }); 

     event(marker,'mouseover',function(){ 
      infowindow.open(map,this); 
     }); 

     event(marker,'mouseout',function(){ 
      infowindow.close(); 
     }); 
} // end of function. 

// Takes in the position passed by the 'placeMarker_and_attachMessage' function and returns a human readable string 
function info_text(position) 
{ 
    var location = position; 
    var latlngStr = location.split(',',2); 
    var lat = parseFloat(latlngStr[0]); 
    var lng = parseFloat(latlngStr[1]); 
    var latlng = new google.maps.LatLng(lat,lng); 
    geocoder.geocode({'latLng': latlng}, function(results, status) 
    { 
     if (status == google.maps.GeocoderStatus.OK) 
     { 
      return results; 
     } 
     else 
     { 
      alert('could not pinpoint location'); 
     } 

    }); 
} 

google.maps.event.addDomListener(window, 'load', initialize); 

回答

0

在您發佈的代碼,count

var marker = placeMarker_and_attachMessage(e.latLng,map,count); 
定義
相關問題