Google Maps API /地理编码 - 我可以通过传递邮政编码来检索回复吗?
问题描述:
问候:Google Maps API /地理编码 - 我可以通过传递邮政编码来检索回复吗?
我在.NET 3.5中放置了一个REST风格的Web服务,它需要一个电话号码并执行反向查找以检索该位置的邮政编码。我现在正在创建一个* .aspx页面,它将向Google Maps API显示请求的输出。该输出将是地图上的多边形,该地图将为美国邮政编码。我想知道如果我只能通过地址参数的http请求中的那个邮政编码。 http://code.google.com/apis/maps/documentation/geocoding/的例子基本上通过了整个街道地址。不太确定ZIP是否足够。
任何人有与此有关的经验?
在此先感谢!
Todd
答
只传递邮政编码应该可以正常工作。
向http://maps.google.com/maps/geo?q=63131&output=json&oe=utf8&sensor=false发出请求可为您提供ExtendedData属性中LatLonBox的有效结果。您必须手动转到该网址,因为如果Google有推荐网址,Google就会拒绝没有API密钥的请求。
答
下面是我使用的一些代码,我只传递了一个邮政编码,它工作正常。
var map = null;
var geocoder = null;
var address = "SW1A 0AA";
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
map.setMapType(G_HYBRID_MAP);
geocoder = new GClientGeocoder();
if (geocoder) {
geocoder.getLatLng(
address,
function(point) {
map.setCenter(point, 13);
var marker = new GMarker(point);
map.addOverlay(marker);
}
);
}
}
}
我也注意到雅虎有一个类似的RESTful地理编码服务。我再次感谢它! – Todd 2009-02-02 18:15:23