Google Map API tutorial on auto Scaling

Source: Internet
Author: User

I spent two nights writing a google map application, using Map api, weather api, and localsearch api. I want to write some articles about Google map API, today, I will write a method for automatically scaling a map to an appropriate level. Here, auto scaling refers to the fact that many Gmarker points have been added to the map, which are available anywhere, in order for them to be displayed on the Map, a Google Map must be used to set a proper zoom level and center point. The method used here is the GLatLngBounds of the Google Map API.

Assume that the Google Map object we created is gmap = new GMap2 (). We add all GMarker stored in an array named markers, and their points are everywhere, all we need to do is to display these points on the map, that is, the automatically scaled map (set auto zoom ).

First we bounds = new GLatLngBounds (); then we use a loop to pass all GLatLng objects in GMarker to bounds, that is, bounds. extend (markers [I]. getLatLng (). After completing the loop, we can use the following code set auto zoom:
Gmap. setCenter (bounds. getCenter (), gmap. getBoundsZoomLevel (bounds );
The following setAutoZoom function is used in combination:

Function setAutoZoom (gmap, markers ){
Var I = markers. length, bounds = new GLatLngBounds ();
While (I --){
Bounds. extend (new GLatLng (markers [I]. y, markers [I]. x ));
}
Gmap. setCenter (bounds. getCenter (), gmap. getBoundsZoomLevel (bounds ));
}

View:Google Map Api setAutoZoom instance

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.