Reputation: 459
Greetings:
I have put together a RESTful web service in .NET 3.5 that takes a phone number and does a reverse lookup to retrieve the ZIP code of that location. I am now creating an *.aspx page that will present the output of a request to the Google Maps API. This output will be a polygon on a map that will be that US ZIP code. I'm wondering if I could just pass in only that ZIP code in the http request for the address parameter. The example at http://code.google.com/apis/maps/documentation/geocoding/ basically passes in the entire street address. Not quite sure if the ZIP would be sufficient.
Anyone had experience working with this?
Thanks in advance!
Todd
Upvotes: 1
Views: 1444
Reputation: 308
Here's some code that I used that I only passed a postal code to and it works fine.
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);
}
);
}
}
}
Upvotes: 0
Reputation: 156075
Passing in just the zip code should work fine.
Making a request to http://maps.google.com/maps/geo?q=63131&output=json&oe=utf8&sensor=false gives you a valid result with a LatLonBox in the ExtendedData property. You'll have to manually go to that URL, since Google refuses requests without an API key if they have a referring URL.
Upvotes: 2