2010-10-13 120 views
1

我想有一個標記的信息窗口的內容,就像下面谷歌地圖信息窗口覆蓋的內容,就像在maps.goole.com

alt text

到目前爲止我的代碼是

loadEmbeddedMap : function() { 
     var script = document.createElement("script"); 
     script.type = "text/javascript"; 
     script.src = "http://maps.google.com/maps/api/js?sensor=false&callback=initEmbeddedMap"; 
     document.body.appendChild(script) 
    }, 
    initEmbeddedMap : function() { 
     var myLatlng = new google.maps.LatLng(40, -80); 
     var myOptions = { 
       zoom: 8, 
       center: myLatlng, 
       mapTypeId: google.maps.MapTypeId.ROADMAP 
     } 
     map = new google.maps.Map(document.getElementById("embeddedGoogleMap"), myOptions); 
     geocoder = new google.maps.Geocoder(); 
     geocoder.geocode({ 'address': $('#userMapAddress').val()}, function(results, status) { 
      if (status == google.maps.GeocoderStatus.OK) { 
       map.setCenter(results[0].geometry.location); 
       marker = new google.maps.Marker({ 
        map: map, 
        position: results[0].geometry.location 
       }); 
       console.debug(results[0]); 
       infowindow = new google.maps.InfoWindow(); 
       var infoWindowContent = "<div><strong>Address:</strong></div>"; 
       infoWindowContent += "<div>"+results[0].address_components[0].short_name+","+results[0].address_components[1].short_name+"</div>"; 
       infoWindowContent += "<div>"+results[0].address_components[5].short_name+","+results[0].address_components[7].short_name+"</div>"; 
       //infoWindowContent += results[0].formatted_address; 
       infowindow.setContent(infoWindowContent); 
       infowindow.open(map, marker); 
      } else { 
       //alert("Geocode was not successful for the following reason: " + status); 
      } 
     }); 
     $('#embeddedGoogleMapWrapper').show(); 
    }, 
上述

代碼輸出該

alt text

如何獲得這些'路線','搜索附近'的東西..?任何幫助感激..

+0

嗨!我也在尋找類似的東西,但要簡單得多。我只想在我的工具提示中包含一個活動網址。通過主動我只是意味着用戶應該能夠點擊它去到所需的網頁。你能指導我嗎?謝謝 – 2010-11-06 11:10:03

+0

你見過這樣的infowindow嗎? – jayarjo 2013-11-02 17:29:49

回答

2

我就開始閱讀

http://code.google.com/apis/maps/documentation/localsearch/devguide.html#hiworld

,我可以看到它可以做你想做的。我不能給你一個直接的答案,但也許是一個線索。 我會在infowindow中創建自己的表單,至少非常接近原始的Google表單,並通過發送這些搜索查詢處理點擊事件。 比你需要處理的搜索結果

http://code.google.com/apis/maps/documentation/localsearch/devguide.html#handle_search_results

做一些測試與

http://code.google.com/apis/ajax/playground/#the_hello_world_of_local_search

例如,你可以得到緯度從localSearch.results [I] .lat等。

我希望你能從中得到一些東西