Google map zoom not show like i save it - google-maps

i am using google maps in order to give some directions from one point to another.
Although, i have set the zoom of the map to 15 the zoom changes after the response of the direction request in order probably to fit the directions into the map.
Does anyone nows how to keep the zoom constant at 15. and focus at the first point?
Thanks in advance.

In your DirectionsRendererOptions, set this option:
preserveViewport: true
See: https://developers.google.com/maps/documentation/javascript/reference#DirectionsRendererOptions

Related

Google Maps Markerclusterer - Manually Set Zoom Level

I use Google Maps Markerclusterer and normally it works great. The problem I am having is when only 1 marker is being displayed (due to users choosing options resulting in 1 marker) the clusterer is setting the zoom level all the way in to the closest level.
Is there any way I can manually set my zoom level and still use the clusterer? I found the MaxZoomLevel feature but that doesn't actually control the zoom. Trying to set the zoom manually at initiate did not work either.
Thanks!

google map zoom after directions

I am using google maps in order to give some directions from one point to another.
Although, I have set the zoom of the map to 15 the zoom changes after the response of the direction request in order probably to fit the directions into the map.
Does anyone nows how to keep the zoom constant at 15. and focus at the first point?
See the documentation for the DirectionsRenderer
preserveViewport: true
will prevent the DirectionsRenderer from changing the zoom.
To center the map on the first point use the map.setCenter function. You will need to parse the response from the directions service and create a google.maps.LatLng object for the first point.
This example shows one way to parse the response:
http://www.geocodezip.com/v3_directions_custom_iconsC.html
(you don't need everything, just the location of the point you want to center on)

Setting map bounds

I have a map which I would like to stay within certain bounds. I have allowed for 2 zoom levels 5 and 8. On zoom level 5 I was able to keep the map from moving by setting the center of the map to adjust by using the setCenter() function on the event of a drag. When I am zoomed in at zoom level 8 I would like to prevent users from dragging the map outside designated limits. The limits are the bounds at zoom level 5. I have tried a few things but with no avail. When I used fitbounds() it kicked me back to zoom level 5. I basically just want to limit how far you can go on the map. Any help would be appreciated.
G
There is a method posted here http://econym.org.uk/gmap/range.htm that works with v2 of the Google Maps API. The technique should work with v3 as well. View source on the example page.
Also see the duplicate question here for refinements on the above method: Google Maps API V3: limit map bounds

Google Static Map API how to specify max zoom level

We have a report that shows where 2 markers are on a map, works great except when the markers are next to each other it zooms in to the highest level of zoom.
We want the min zoom to be open, but set the max zoom to a certain level. I have looked through the Google Static Map documentation, and cant see where to do it.
Does anyone know if this is possible using the static map api?
Cheers.
Google does not have that feature in place. Here is a feature request:
Issue 3909
http://code.google.com/p/gmaps-api-issues/issues/detail?id=3909
Please vote!
Well it is sort of not straight forward to get it with static maps. You can omit specifying the zoom and hope google will choose what it thinks best.
Anyway this is how I got rid of it. I had my own zoom up / zoom down buttons to show up next to the map image. Upon click, I increase or decrease the current zoom value and reload the map image.
I know it's not pretty, but it gets the job done.
I have not tried that for static maps but it works for me in normal map:
google.maps.event.addListener($map, 'zoom_changed', function(){
if($map.getZoom()<4){$map.setZoom(4);}
if($map.getZoom()>14){$map.setZoom(14);}
});
Here I am limiting both max and min zoom.
Hope it helps
K
http://maps.google.com/staticmap?markers=-21.7164,35.4384&size=640x640&key=your-api-key&format=png8&maptype=roadY&zoom=8
Note the zoom querystring parameter
I found the following code from this URL:
http://code.google.com/apis/maps/documentation/javascript/events.html
google.maps.event.addListener(marker, 'click', function() {
map.setZoom(8);
});
Instead of adding listener, you could do document.onload(function() {
map.setZoom(8));

How can I have a smooth animated move between 2 Google Maps locations?

When clicking from one marker to another in Google Maps, the map screen animates the move smoothly if both markers are within them initial map view but jumps if one of the markers is off screen.
I'm trying to set up a map which has several locations within the main map area but has one which is 'off screen'. I have a signpost icon to the more distant location within the initial map area which I want to smoothly scroll to the off screen location when clicked (so as to give a better sense of it's relative location). I can't find anything in the Maps API which would let me do this however.
I could zoom out, move and then zoom in again but this looks a bit jarring. Am I missing something in the API, or does anyone have any suggestions?
Unfortunately, I don't think this is possible (without a change from Google). From the v3 API reference for panTo:
Changes the center of the map to the given LatLng. If the change is less than both the width and height of the map, the transition will be smoothly animated.
which implies that if that change is not less than the dimensions of the map, the transition won't be smoothly animated. The other pan methods are similar.
You could try moving in multiple steps but that's a bit of a hack and I suspect the result will be poor.
Sorry that's not very helpful (I have the same problem).
For me this method works, but i'm using Google Maps API v2.
LatLng latLng = new LatLng(lat,lng);
map.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, ZOOM_FACTOR));
This animates the camera from current position to the new one.
If you are using Gmaps API V2, then you can implement smooth animated move very easily by using panBy() method. You have to use fromLatLngToContainerPixel() method to find the amount of pixels to pan by.
Here is the bit of code:
var newLoc = map.fromLatLngToContainerPixel(new GLatLng(lat, lng));
map.panBy(new GSize( newLoc.x, newLoc.y ));
However, what I am trying to do is to achieve the same thing in maps API V3, but sadly fromLatLngToContainerPixel() method does not work anymore the way it did :(