我無法弄清楚如何在我的谷歌地圖中實現搜索框。我有它在哪裏用戶可以從窗體中挑選一些東西,並在地圖上加載標記。現在我想添加他們可以在Google地圖上輸入城市和州的位置,例如在maps.google.com上。這可以通過API v。3來完成嗎?Google Maps API 3搜索框
回答
此任務在Google地圖中沒有完整的「小部件」。但它很容易實現。在HTML中,您可以有一個文本字段和一個按鈕「搜索」。 (相反,您可以在文本字段中處理Enter鍵)。
<input type="text" id="search_address" value=""/>
<button onclick="search();">Search</button>
在Javascript中實例化和使用地理編碼:
var addressField = document.getElementById('search_address');
var geocoder = new google.maps.Geocoder();
function search() {
geocoder.geocode(
{'address': addressField.value},
function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var loc = results[0].geometry.location;
// use loc.lat(), loc.lng()
}
else {
alert("Not found: " + status);
}
}
);
};
我該如何獲得附加信息,如該地點的名稱或地址? – Alp
@Alp:上面的用例描述了您已經知道名稱或地址並且想要獲取相應位置(lat,lng)的情況。如果您想在某個位置附近找到有趣的地方,那麼您可以查看[Google地方](http://code.google.com/apis/maps/documentation/places/)。 – Jiri
@Alp我需要一個確切的東西來請求你的評論,這就是你要找的:https://developers.google.com/maps/documentation/geocoding/#Geocoding你可能已經找到了什麼你現在正在尋找,但仍然;) – mavili
- 1. Google Maps API商業搜索
- 2. Google Maps API 3
- 3. google-maps-api-3
- 4. Google Maps API 3&jQTouch
- 5. Google Maps API 3 referrerNotAllowedMapError
- 6. Google Maps API文本搜索位置
- 7. Google Maps API - 附近位置搜索
- 8. Google Maps API 3 - 像在maps.google.com上搜索地圖
- 9. Google Maps API Javascript:激活地點搜索框中標記的infowindows
- 10. Anchor id取消選擇google maps api搜索框
- 11. Google Maps API Places搜索獲取搜索結果數量
- 12. Google Maps Api版本3
- 13. Google Maps API 3怪異
- 14. Google Maps API v3:爲什麼Google Maps API V3和Google Maps的搜索結果之間存在不一致?
- 15. Google Maps API
- 16. 檢索Google Maps API密鑰
- 17. Google api搜索框結果編號
- 18. Google Maps API圖像
- 19. Google App Engine和Google Maps在Python中搜索近距離搜索
- 20. Google maps sdk ios搜索標記
- 21. Google Maps API v2 vs Google Maps API v3?
- 22. Google Static Maps Api?
- 23. Grails + Google Maps API
- 24. Google AJAX搜索API
- 25. Google Ajax搜索API
- 26. [google-maps-api-3] [Geocoder]特殊字符:Ñ
- 27. Google Maps API 3加載圖標
- 28. 如何限制Google Maps API的搜索框結果到一個國家/地區?
- 29. Google Maps JavaScript API,用於在地圖上顯示路線的搜索框
- 30. zombie.js和Google Maps API
我不知道如何與谷歌的搜索框完成,但有幾個例子,可以幫助你開始你的問題[地理編碼示例](http://code.google.com/apis/maps/documentation/javascript/examples/geocoding-simple.html)[使用jquery進行地理編碼的示例](http://tech.cibul.net/ geocode-with-google-maps-api-v3 /) – Jorge