我无法弄清楚如何在我的谷歌地图中实现搜索框。我有它在哪里用户可以从窗体中挑选一些东西,并在地图上加载标记。现在我想添加他们可以在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