当前位置: 动力学知识库 > 问答 > 编程问答 >

zipcode - Is it possible to send a zip code to maps V3 API to return a map centered on that zip code?

问题描述:

I need to display a map on a web page - I have the user's address info, but for security purposes I need the map to be centered on the centroid point of their zip code or city, not their specific address.

Is it possible to submit only a zip code to the Google maps V3 API and have it return a map of a postal code / zip-code?

Or do I have to first geocode the zip code and submit the lat/long?

This is how I was doing it using Yahoo...

//assign the zipcode from the database to the zipcode variable

zipCode = oUser("zipCode")

<script type="text/javascript"

src="http://api.maps.yahoo.com/ajaxymap?v=3.8&appid=x">

</script>

// create the container

<div id="map" class="map">

<script type="text/javascript">

// Create a map object

var map = new YMap(document.getElementById('map'));

// Display the map centered on the zipcode

map.drawZoomAndCenter("<%=zipCode%>", 5);

</script>

If you go to google.com/maps and enter a 5 digit US zip code, the website will return a map that is centered on the central point of that zip code. The script above did the same thing on my website (until Yahoo discontinued its map service).

I’d like to do the same thing using the Google API – but everything I’ve seen so far indicates that I have to send the long/lat string of the zip-code centroid point to the API - which is fine (we have a zip-code/long/lat table in the database) – it just requires more server work on our end – or on Google’s if I geocode a zipcode on the fly). I’d like to keep this as efficient as possible and send only the postal_code if possible.

Can that be done?

Thanks,

  • Michael

分享给朋友:
您可能感兴趣的文章:
随机阅读: