In previous post I came up with formula on how to calculate zoom level using “range” information in KML. To get the formula I compared zoom levels in maps.google.com with views from google earth.
I opened google map page, resized my windows so the map size was 500×500 and set zoom level to maximum – 18. Then I opened google earth, made sure map size is 500×500 and navigated to same view as I had on web page. Eye altitude in google earth was 214m.
That means if map size is 500×500, and range value returned from google geocoder is 214m I should set the zoom level to 18. Easy.

I did the numbers for various zoom levels and map sizes and in the end I somehow conjured the formula:
zoom = 18-log2(3.3*range/sqrt(x*x+y*y))
Problem No2:
I do all above calculations on the server and send results to the browser. For my application I also need to know coordinates of visible area on a map. Somehow – based on center of the map, zoom level, and map size, I should be able to find right coordinates.
Instead I found easier way that makes even my hard sweated formula useless.
Instead of getting data in KML format: http://maps.google.com.au/maps?q=Poprad,Slovakia&output=kml
I am getting them in JS format:
http://maps.google.com.au/maps?q=Poprad,Slovakia&output=js
Result that comes back is a html page with some javascript that (besides lots of other crap) bear this bit:
viewport: {center: {lat:49.057037000000001, lng:20.304269999999999}, span: {lat:0.099098000000000006, lng:0.169104}
so now I have area for my location and I can query my DB for points in that area. I can also send span to the browser and use GMap.getBoundsZoomLevel(bounds) method to get the right zoom. Easy.
Seeing is believing – click on the link to check out the demo: http://homemap.com.au/throwless-0.3/search.html
Right now I am just using the GClientGeocoder to do my map searches. When a search is ambiguous I get a bunch of results, but each one has a lat,lng tied to it. I then make a link for each result that, when clicked, moves the marker to the result’s corresponding location. I would also like it to zoom to the appropriate level, which is why I have been looking at your posts. When I looked at http://maps.google.com/maps?q=search&output=js (’search’ query gives 8 results using the geocoder) I only saw one ‘viewport: { center: {…}, span: {…}}’ section. When I looked at http://maps.google.com/maps?q=search&output=kml there were no ‘range’ tags. Is there no way to do this with an ambiguous search? Would I have to use the geocoder like I was, then use your method on each geocoder result? Also, are you just fetching the url and parsing the file, or is there some easy implementation for these urls?
I am not sure if there is a service that will return viewport or range for multiple destinations. You may need to do separate request for each of them.
I am making the requests and parsing of files on the server and return back to browser already parsed data.
Link http://homemap.com.au/throwless-0.3/search.html dont work