How calculate zoom for polyline?

972 views
Skip to first unread message

Shaliko

unread,
Jun 8, 2010, 11:24:44 AM6/8/10
to Google Maps JavaScript API v3

When I create Gmap she needed to establish the center and zoom

Because of this route is not positioned at the center - this is an
example http://grab.by/4OD6

How get a zoom which displays my polyline objects map?

My code:

var TrainingGMap = Class.create({
initialize: function(div_id, points, options) {
this.options = Object.extend({}, options)
this.points = points;
var latlng = new google.maps.LatLng(this.points[0].lan,
this.points[0].lon);
this.map = new google.maps.Map(document.getElementById(div_id), {
zoom: 12,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
});

var line = new Array();
for (var i = 0; i < this.points.length; i++) {
line[i] = new google.maps.LatLng(this.points[i].lan,
this.points[i].lon);
}

var polyline = new google.maps.Polyline({
path: line,
strokeColor: "#aa0000",
strokeOpacity: 1.0,
strokeWeight: 5
});

polyline.setMap(this.map);
var polylineBounds = new google.maps.LatLngBounds(line.first(),
line.last());
this.map.setCenter(polylineBounds.getCenter());
}
});

geoco...@gmail.com

unread,
Jun 8, 2010, 2:19:01 PM6/8/10
to Google Maps JavaScript API v3
On Jun 8, 8:24 am, Shaliko <hashtr...@gmail.com> wrote:
> When I create Gmap she needed to establish the center and zoom
>
> Because of this route is not positioned at the center - this is an
> examplehttp://grab.by/4OD6

Why a picture? Why not a link to your map as requested in the posting
guidelines?

>
> How get a zoom which displays my polyline objects map?

GLatLngBounds.extend
http://code.google.com/apis/maps/documentation/javascript/reference.html#LatLngBounds

with all the points in the polyline would be one suggestion.

-- Larry
> });- Hide quoted text -
>
> - Show quoted text -

Shaliko

unread,
Jun 9, 2010, 2:19:45 AM6/9/10
to Google Maps JavaScript API v3
> GLatLngBounds.extendhttp://code.google.com/apis/maps/documentation/javascript/reference.h...
>
> with all the points in the polyline would be one suggestion.

Can an example?

I think I did not understand.

On 8 июн, 22:19, "geocode...@gmail.com" <geocode...@gmail.com> wrote:
> On Jun 8, 8:24 am, Shaliko <hashtr...@gmail.com> wrote:
>
> > When I create Gmap she needed to establish the center and zoom
>
> > Because of this route is not positioned at the center - this is an
> > examplehttp://grab.by/4OD6
>
> Why a picture? Why not a link to your  map as requested in the posting
> guidelines?
>
>
>
> > How get a zoom which displays my polyline objects map?
>
> GLatLngBounds.extendhttp://code.google.com/apis/maps/documentation/javascript/reference.h...

Fredrik Bonander

unread,
Jun 9, 2010, 2:31:21 AM6/9/10
to google-map...@googlegroups.com
After working with the above for sometime I've grown quite fond of it. Have somebody heard if Google will ever release this outside the maps api? Or if the source code is avalible somewhere?

..fredrik

geoco...@gmail.com

unread,
Jun 9, 2010, 9:16:04 AM6/9/10
to Google Maps JavaScript API v3
On Jun 8, 11:19 pm, Shaliko <hashtr...@gmail.com> wrote:
> > GLatLngBounds.extendhttp://code.google.com/apis/maps/documentation/javascript/reference.h...
>
> > with all the points in the polyline would be one suggestion.
>
> Can an example?

If you had posted (or can post) a link to your map as requested in the
posting guidelines, you might get one.

http://groups.google.com/group/google-maps-js-api-v3/browse_frm/thread/2b3f101fd509919e

-- Larry
Reply all
Reply to author
Forward
0 new messages