从Zip Code获取LatLng - Google Maps API [英] Get LatLng from Zip Code - Google Maps API

查看:138
本文介绍了从Zip Code获取LatLng - Google Maps API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


推荐答案

我想要的是一些简单的示例代码,显示了如何从输入的邮政编码或城市/州获取latlng元素。 / div>

难道你不能直接调用以下代码替换{zipcode}的邮政编码或城市和州
http://maps.googleapis.com/maps/api/geocode/json?address= {zipcode}

Couldn't you just call the following replaceing the {zipcode} with the zip code or city and state http://maps.googleapis.com/maps/api/geocode/json?address={zipcode}

Google地理编码

以下是使用JavaScript进行地理编码的链接: Geocode walk-thru 。如果您需要特定的纬度/经度数字,请调用geometry.location.lat()或geometry.location.lng()( API for google.maps.LatLng class

Here is a link with a How To Geocode using JavaScript: Geocode walk-thru. If you need the specific lat/lng numbers call geometry.location.lat() or geometry.location.lng() (API for google.maps.LatLng class)

获取lat / lng的示例:

EXAMPLE to get lat/lng:

    var lat = '';
    var lng = '';
    var address = {zipcode} or {city and state};
    geocoder.geocode( { 'address': address}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
         lat = results[0].geometry.location.lat();
         lng = results[0].geometry.location.lng();
        });
      } else {
        alert("Geocode was not successful for the following reason: " + status);
      }
    });
    alert('Latitude: ' + lat + ' Logitude: ' + lng);

这篇关于从Zip Code获取LatLng - Google Maps API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆