GLatLngBounds - wrong center and zoom level

I'm trying to use GLatLngBounds to make all the markers on the map visible. Below is a small example of what I'm doing.

INV.createMap = function(containerId) { var map = null; var geocoder = null; var bounds = new GLatLngBounds(); if (GBrowserIsCompatible()) { map = new GMap2(document.getElementById(containerId), { size: new GSize(600, 300) }); map.setCenter(new GLatLng(54.729378425601766, 25.279541015625), 15); map.addControl(new GSmallZoomControl()); geocoder = new GClientGeocoder(); } return { markAdress: function(address, infoContentHtml) { if (map !== null && geocoder !== null) { geocoder.getLatLng(address, function(point) { if (point) { var marker = new GMarker(point); GEvent.addListener(marker, 'mouseover', function() { if (!map.getInfoWindow().getPoint().equals(this.getLatLng())) { this.openInfoWindowHtml(infoContentHtml); } }); map.addOverlay(marker); bounds.extend(point); } }); } }, finalize: function() { map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds)); } }; };

Usage:

var m = INV.createMap('whatever'); var addresses = ... for (var i = 0, l = addresses.length; i < l; i++) { m.markAdress('address...', 'htmlInfo...'); } m.finalize();

The problem is that the zoom level is completely wrong (waaay too zoomed out) and the markers appear on the left top corner of the map for some reason (but all of them are visible).

What am I doing wrong?

EDIT: Ignore this question. I've made a stupid mistake - I overlooked the fact that GClientGeocoder makes asynchronous requests so the finalize() method is called too early.

-------------Problems Reply------------

The last argument of the function call below specifies the zoom level:

map.setCenter(new GLatLng(54.729378425601766, 25.279541015625), 15);

This article talks a bit about zooming. So the zooming level is a bit too high.

Further this tutorial tells you how to fit the map zooming to properly display a set of markers.

Hope this helps

Category:javascript Views:0 Time:2009-06-02

Related post

  • How can I get the zoom level, latitude/longitude values, and center of the Map when zooming in/out? 2010-08-19

    I am implementing an application based on the MapKit using the iPhone SDK. Now I just need a method to get the event when we drag, zoom in/out on the Map. The method is like this: -(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)anim

  • Google Maps API v3: How to Set Zoom Level And Map Center To User Submitted Location? 2011-12-21

    I have used this tutorial from Google to build a web app that finds the closest store from the user entered location: http://code.google.com/apis/maps/articles/phpsqlsearch_v3.html I have my app almost working the way I want it, upon page load, the m

  • Android Google Maps - how to set the zoom level (and center) of map to display all my geoobjects? 2012-01-15

    I use google api 2.2. How should I set zoom level(maybe center as well) to display all my geo-objects from ArrayList or Array? I should be dependent on landscape/portrait orientation and maybe screen resolution? --------------Solutions------------- I

  • How to get Google Maps API to set the correct zoom level for a country? 2010-02-15

    Is there a was of automatically setting the zoom level based on the size of the country that the map has been centered on? maps.google.com does exactly what I need, so, for example, if I search for Russia I get a zoom level such that Russia just fits

  • How to set the Google Map zoom level to show all the markers? 2010-03-02

    How do I set the zoom level to show all the markers on Google Maps? In my Google Map there are different markers in different positions. I want to set google map zoom level based on the range of markers (that means in the view of google map, i want t

  • How to set google map custom zoom level dynamically? 2010-03-11

    I am working with google map. According to requirements i need to set different zoom level that is dependent to my search query.If there are multiple location on the map in country then map should focus the country. Other scenario is , if there are d

  • Calculate zoom level on google maps control in C# 2011-07-05

    I'm using GoogleMap Control have a collection of markers with Geo locations. I can calculate the min and max lat longs and find the center point on where to center the map but I also need to calculate the zoom level programmatically. Does anyone how

  • How to calculate appropriate google maps zoom level 2012-04-04

    I have a tricky question...I am using the google maps static API to create an image of a map with markers on it. What I am struggling to do is calculate the appropriate zoom level, given the positions of the two markers I want to display. I have lati

  • Get max viewing distance from current zoom level with Google Maps API 2009-09-07

    When loading some directions the map adjusts to the appropriate zoom level. Then I request for several markers in the database within a certain radius from the map's center. How do i get the correct radius value depending on the current zoom level? T

  • Is there way to limit MKMapView maximum zoom level? 2009-10-28

    the question is - is there a way to limit maximum zoom level for MKMapView? Or is there a way to track when user zooms to the level where there's no map image available? --------------Solutions------------- You could use the mapView:regionWillChangeA

  • May I restrict zoom levels of MKMapView? 2009-10-28

    the question is - is there a way to limit maximum zoom level for MKMapView? Or is there a way to track when user zooms to the level where there's no map image available? --------------Solutions------------- You could use the mapView:regionWillChangeA

  • How to detect page zoom level in all modern browsers? 2009-11-11

    How can I detect the page zoom level in all modern browsers? While this thread tells how to do it in IE7 and IE8, I can't find a good cross-browser solution. Firefox stores the page zoom level for future access. On the first page load, would I be abl

  • MkMapView Zoom Level 2010-04-26

    I m using MkMapView with google maps.I succeed to show map view and address with annotation pin.But I want increased zoom level.How Can I Set it programmatically???? -(void)showMyAddress { //Hide the keypad MKCoordinateRegion region; MKCoordinateSpan

  • set zoom level when marker is removed 2010-04-26

    using javascript google-maps api I currently have it setup to remove a maker I set it up when I am adding a location like so function addLocation(map,location) { var point = new GLatLng(location.lat, location.lon); var marker = new GMarker(point); ma

  • How to get all visible markers on current zoom level 2010-05-25

    Here are some points: 1) I have some markers on the map and records associated with it on the right panel besides the map. They are connected via numeric id, which is stored as a property of marker. 2) All the markers are stored in an array. 3) When

  • Google Maps v3: Enforcing min. zoom level when using fitBounds 2010-06-07

    I'm drawing a series of markers on a map (using v3 of the maps api). In v2, I had the following code: bounds = new GLatLngBounds(); ... loop thru and put markers on map ... bounds.extend(point); ... end looping map.setCenter(bounds.getCenter()); var

  • Google-Maps v3: How to change the map style based on zoom level? 2010-06-25

    I am using the new Google Maps v3 STYLED MAP. I want to change how the map is Styled based on the zoom level. I have the following pseudo-code, how do change my map-style based on the zoom level? var myOptions = { zoom: zoom, center: latlng, disableD

  • Google Maps v3 - Automating Zoom Level? 2010-07-14

    I'm having the possibility to have multiple markers. Currently i'm using the map.fitBounds(bounds); In my css to have the map resized (bounds contains multiple latlng's). What am i doing wrong? Because it won't use the best zoom level :-( Edit: Javas

  • MKMapView setRegion "snaps" to predefined zoom levels? 2010-08-31

    Can anyone confirm that setRegion "snaps" to predefined zoom levels and whether or not this behavior is as designed (although undocumented) or a known bug? Specifically, it appears that setRegion snaps to the same zoom levels that correspond to the z

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.172 (s). 11 q(s)