I have set of markers on Google map.
Is it possible to center the map in the way that all markers will be visible, and zoom level will also be auto adjusted?
Exactly the same way how Goolge Static Maps API does when you specify markers and do not specify center/zoom parameters (Implicit Positioning of the Map).
You can use var myBounds = google.maps.LatLngBounds() and basically extend all the points you have. Once you have all the points in the LatLngBounds() you can use your map.fitBounds(myBounds); and all marker should be visible and centered.
do you wish me to prototype a jsfiddle?
Related
In My application I have to show split of markers which means all markers should be visible. If one marker geo distance is longer than others it should show like below.
In Google Dynamic Map API which is possible by “Spiderfier”. Refer the link below and below image.
http://jawj.github.io/OverlappingMarkerSpiderfier/demo.html
Like this option, I have to split of all markers in Google Static MAP API.
Any possibilities there to visible all markers ?
Static Map URL:
http://maps.googleapis.com/maps/api/staticmap?sensor=false&channel=Resivalue&scale=2¢er=29.900598698735365,-95.69396430030821&zoom=13&size=1300x500&maptype=roadmap&markers=color:green%7Clabel:S%7C29.89357,-95.68815999999998&markers=color:pink%7Clabel:1%7C29.893167,-95.68737599999997&markers=color:pink%7Clabel:2%7C29.893904,-95.688424&markers=color:pink%7Clabel:3%7C29.892301,-95.68776500000001&markers=color:pink%7Clabel:4%7C29.892343,-95.68866200000002&markers=color:pink%7Clabel:5%7C29.894404,-95.689029&markers=color:pink%7Clabel:6%7C29.893235272621563,-95.68611836505124&markers=color:pink%7Clabel:7%7C29.892402,-95.68687699999998&markers=color:pink%7Clabel:8%7C29.891934,-95.688918&markers=color:pink%7Clabel:9%7C29.919640547998576,-95.72656616430663
As stated here
Google Static MAP API Disadvantages :
The main disadvantage is the lack of a map interactivity – if we
need a map to scale, move or if we need to roll down a window after
clicking on a marker; Google Static Maps is not a solution for us.
URL address of a map has a restricted length (2048 symbols) which
sometimes may make impossible to present all needed content on a
map.
Limits also apply in the case of own images markers placing on a map
– in this case it is 4096pixels (64 x 64 px).
I have an application that downloads static images off Google maps, with markers placed where I want them (Placed by passing arguments into the Google Static Maps URL). However, I also need to be able to click the markers. I figured I could convert the x and y coordinate is the click to lon/lat, and then figure out that way which marker was clicked, but I haven't found that too easy.
I know the dimensions of the map in pixels, the zoom level, and the centre point of the map in pixels and lon/lat, so I followed this blog post. Unfortunately this didn't work.
Does anyone know how I could do this, or know another way I could figure out if a marker has been clicked? I'm forced to use the Static maps unfortunately, so I can't do any of it with the JavaScript API
See:
http://home.provide.net/~bratliff/largetiles/
or
http://home.provide.net/~bratliff/harbor/
It is not exactly what you are doing but it does demonstrate Mercator projection conversions & cross-browser mouse events.
The LatLngBounds function needs the corner points!
How to find the boundary points with center and zoom level given?
Is there Google API V3 which achieves this?
Or can this be done someway with the static maps?
Are you referring to the boundary points of the visible map? If so, you can use the getBounds method of the map object.
var llb = map.getBounds();
If you are using the geocoder, it returns a suggested viewort (that is a google.maps.LatLngBounds() object).
See this similar question:
Google Maps API zoom after setcenter
If you only have the center coordinates and the zoom, use them to initialize the map, listen for the bounds_changed event, then use the map.getBounds() function.
All of the above are described in the documentation
I'm working in a Java Me application that uses google static maps. The problem is that I need to get the zoom and center that fits all markers, and I need to add some labels in some coordinates on the map. How can I do this? I need a function in the server or in the midlet to get this parameters, I can't use javascript.
You don't need to calculate it on your own.
When you supply markers, usually the map will have a viewport to show all markers.
To modify the viewport use the visible-parameter.
Referring to the comments:
Pseudo-Code for calculating the center from a couple of Points:
latitude: (maxLatOfAllPoints+minLatOfAllPoints)/2
longitude:(maxLngOfAllPoints+minLngOfAllPoints)/2
I have had the same problem. Don't use "&zoom=xx" in your url, the map will auto-fit for all your markers!
Define bounds object
bounds = new google.maps.LatLngBounds();
When you create and place marker on the map extend bondes with marker position.
bounds.extend(mPosition);
where mPosition is a google new google.maps.LatLng(0,0) object, the same that you use during marker creation.
at the end ot you can create a link for click or just run.
map.fitBounds(bounds);
That is it.
Using Google Maps InfoBox -
http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/docs/reference.html
Currently the map will scroll - pan control - when your infobox is outside of the bounds of the map.
I'm looking for a way to detect if the infobox will be outside of the bounds of the map, and if so the position is switched (currently I have the infoBoxAnchor set at 9,2) - so set the infoboxanchor in the opposite x direction.
Anyone done anything like this?
Thanks.
Could be tricky - infowindows are dynamically sized based on the content in them. What you could do, is in the InfoWindowOptions, set disableAutoPan=true. This will prevent the map panning to display the infowindow. Then I'm guessing you could use jQuery (or any other JS you like) to figure out:
the size of the infowindow based on the position where it's anchored to on the map,
is the entire infowindow visible
if not, move the infowindow's position
Related:
Auto adjustment of InfoWindow position on Google Maps
Google Maps Mashup with Intelligently positioning InfoBox
Google Maps: How to prevent InfoWindow from shifting the map
And a possible solution (thanks to above links) at http://gmaps-samples-v3.googlecode.com/svn/trunk/smartinfowindow/smartinfowindow.html