google.maps.Geocoder反向地址解析怎么得到英文地址?

ljdone 2014-01-22 12:32:36
客户端脚本中有这么一段,能得到中文地址。
但是最近有英国客户需要使用,怎么能得到英文地址呢,请各位指教!

var latlng = new google.maps.LatLng(dLatitude, dLongitude);
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'latLng': latlng }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
var sAddress = results[1].formatted_address;//中文地址

}
}
});
...全文
292 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
t101lian 2014-01-23
  • 打赏
  • 举报
回复
  • 打赏
  • 举报
回复
你可以指定引入api的语言格式,那么返回结果就是对应语言的 language=en 显示英文
<script src="http://maps.google.com/maps/api/js?sensor=false&libraries=places&language=en" type="text/javascript"></script>
下面示例 解析成英文
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="http://maps.google.com/maps/api/js?sensor=false&libraries=places&language=en" type="text/javascript"></script>
<title>谷歌地图地理解析和反解析geocode.geocoder详解</title>
<meta name="author" content="yanue" />
<meta name="copyright" content="powered by yanue" />
<link rel="site" href="http://map.yanue.net/" />
<script type="text/javascript">
window.onload = function() {
//初始化地图
var map = new google.maps.Map(document.getElementById("map_canvas"),{
    center : new google.maps.LatLng(26.57, 106.72),
    zoom : 8,
    mapTypeId : google.maps.MapTypeId.ROADMAP
});
//实例化Geocoder服务
var geocoder = new google.maps.Geocoder();
 
//1.地理解析过程
//请求数据GeocoderRequest为address,值为'贵阳'
geocoder.geocode({address:'贵阳'},function geoResults(results, status){
  //这里是回掉函数(即结果处理函数)
  //状态为Ok说明有结果
  if (status == google.maps.GeocoderStatus.OK) {
      //一般情况下会有多个结果
      //第一个结果为最佳匹配的结果(匹配地名最全的结果),这里只去第一个,其他的可以根据需要自己循环出来
      //格式化过后的地址
      alert('地理解析结果:'+results[0].formatted_address);
      //geometry是一个包含bounds(界限),location(纬度/经度坐标),location_type和viewport(视图范围)
      //获取解析后的经纬度      
        alert('地理解析结果:'+results[0].geometry.location);
  }else{
    alert(":error " + status);
  }
});
 
//2.地理反解析过程
//请求数据GeocoderRequest为location,值类型为LatLng因此我们要实例化经纬度
geocoder.geocode({location:new google.maps.LatLng(26.57, 106.72)},function geoResults(results, status){
  //这里处理结果和上面一模一样
  if (status == google.maps.GeocoderStatus.OK) {
      alert('地理反解析结果:'+results[0].formatted_address);
  }else{
    alert(":error " + status);
  }
});
}
</script>
</head>
<body>
    <div id="map_canvas" style='width: 300px; height: 200px;'></div>
</body>
</html>

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧