2 questions on adjusting zooming based on address detailness, or vice versa respectively:
just like google map, when users type in 'usa', 'Washington', or 'New York', google map will zoom to different levels. It depends on how specific the user input is.
I have read through the google map api docs about automating this, but w开发者_如何学运维ith no avail. Are there any easy ways to acheive this?
In the google api docs about reverse geolocating, formatted_address could be of 8 levels of "detailness"
if the user zoom to a specific level and define a marker there, are there any easy ways to return back the "corresonding detail level" of formatted_address? Or I need to hard code the logic myself?
P.S. I don't need the whole detailed code, I just need the proper way of thinking to do it easily, better automatically.
I have read through the google map api docs about automating this, but with no avail. Are there any easy ways to acheive this?
Re 1. when you send a geocoding request to Google:
http://maps.google.com/maps/api/geocode/xml?address=usa&sensor=false
you will get viewport
and bounds
elements. These rectangles show the bounds of the item found, and the optimal map viewport to show it in full. It works for any kind of entity, like countries, states, and cities.
- <viewport>
- <southwest>
<lat>-5.7034477</lat>
<lng>-161.2792988</lng>
</southwest>
- <northeast>
<lat>64.7366415</lat>
<lng>-30.1464832</lng>
</northeast>
</viewport>
you can zoom the map to fit one of those using the fitBounds()
method.
Re 2.)
question 2 is about adjusting the displayed address detailness based on zooming. when the map is manually zoomed to a level that no streets could be recognised, the rough region information should be displayed rather than the detail street address one
as far as I know, that is not possible: There is no way to get hold of the current detail level. You would have to estimate it manually according to the numeric zoom level - when should I show cities, when should I show roads etc.
You want to look for the getBound method of the Google-Api. A Google map bound is defined by its spatial index. You want to look for a tile index where you can find your location. getBound simplified to find this index, otherwise you need to calculate the index using a space-filling-curve or a spatial index. You want to look for Nick's spatial index quadtree hilbert curve blog.
精彩评论