客户端的反向地理代码(Google Maps V3 API)
Reverse Geocode on Client Side (Google Maps V3 API)
如何使用Google Maps V3 API在客户端执行反向地理代码?从地址到LatLng的正向地理编码是直接的(下面的代码(,但如何对反向地理编码进行同样的操作?
正常地理代码:
geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
过程完全相同,只是提供了LatLng对象,而不是向地理编码函数提供地址对象
反向地理代码:
var input = document.getElementById("latlng").value;
var latlngStr = input.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) {
if (results[1]) {
map.setZoom(11);
marker = new google.maps.Marker({
position: latlng,
map: map
});
infowindow.setContent(results[1].formatted_address);
infowindow.open(map, marker);
} else {
alert("No results found");
}
} else {
alert("Geocoder failed due to: " + status);
}
});
直接来自Google 的示例
希望能有所帮助。
相关文章:
- 单击超链接时,如何使用Google Maps API v3缩放地图
- 使用Google Maps API向标记添加多个字符
- Google Maps API OverlayView()在AngularJS指令中不起作用
- 使用Google Maps API驱动时间多边形
- 使用Google Maps JavaScript API v3和Geocoding API映射多个位置
- 在for循环中使用多维数组设置google.maps.Marker图标
- 可扩展的画布作为Google Maps Javascript API中的覆盖
- 在自动完成中使用Google Maps Places API;API不工作
- google.maps.event.addDomListener(window, 'load', fun
- 根据PHP中数组的长度在Google Maps API中循环遍历标记
- 加载Google MAPS API v3的JSON数据
- 如何使用Dojo引用Google Maps事件中的包含类
- Javascript:Google Maps API:如果地图加载在隐藏容器中,则为空白地图
- 如何在Ionic/Codova应用程序中保护我的Google Maps Javascript V3 API密钥
- 来自JSON数组的Google Maps API生成器
- URL http://maps.google.com/maps?saddr=Start&daddr=end 继续
- Google Maps/Google Places:getPlace 和 getDetails 方法之间有区别吗?
- 如何在像maps.google.com这样的标记上右键添加基本方向
- 谷歌地图:放大/缩小与平移到特定点,如maps.google.com上下文菜单
- maps.google 地理编码 Jquery 调用与国家/地区代码