Setting map bounds - google-maps

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

Related

Google Map API: How to skip loading tiles if current zoom level > max zoom level at special area

I'm working on Google Map API v3.
But when zoom in with big level zoom at Sea Area. Google Map API return 404 error.
But on https://www.google.com/maps/#28.5698026,-78.3196671,8000m/data=!3m1!1e3
It's still working without 404 Error. Look like they skip loading new tiles if Google Map API return 404? I'm not sure about this.
This is my result:
This is Google Map result:
Thank you for reading my question!
You can use the Maximum Zoom Image Service to get the current maximum zoom Google has for imagery at a given location. You can connect this to the center_changed event to react to the user panning the map.
I wrote a small example on how to do this here:
https://jsfiddle.net/SirWolf/m684t5yp/
There is however no way to have a mix of different zoom levels in one view.

Google Maps Static API - Custom zoom with markers

I am creating an application that downloads images from maps using the Google Maps Static API. I would want to decide the zoom level when having markers on the map (right now the zoom is set automatically so that all markers are shown in the image). Does anyone know if this is possible?
Right now the zoom is set automatically so that all markers are shown in the image
You are halfway there. Once done, get the resulting the zoom level: map.getZoom();
However, I think your app violates Google's terms as it is forbidden to copy their content.
According to the documentation, you can use the center and zoom parameters to configure the map (they aren't required with markers):
Location Parameters
center (required if markers not present) defines the center of the map, equidistant from all edges of the map. This parameter takes a location as either a comma-separated {latitude,longitude} pair (e.g. "40.714728,-73.998672") or a string address (e.g. "city hall, new york, ny") identifying a unique location on the face of the earth. For more information, see Locations below.
zoom (required if markers not present) defines the zoom level of the map, which determines the magnification level of the map. This parameter takes a numerical value corresponding to the zoom level of the region desired. For more information, see zoom levels below.
example URL:
https://maps.googleapis.com/maps/api/staticmap?center=42,-72&zoom=5&size=400x400&markers=color:blue%7Clabel:S%7C11211%7C11206%7C11222&format=jpg
resulting image:

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!

On my Google Maps when I zoom out beyond level 10 all my markers disappear

My google maps work fine at a zoom level higher than 10, but if I zoom out my markers disappear. I cant see where the error is. Have tried using v3 and v2. Also changing from .png markers to .gif. Have tried with fewer points on the map.
Its the same problem across all the browsers.
Thanks for helping...
http://test.onionring.co.uk/map-towns.asp?region=Cheshire
Nick
This is your problem (the marker manager is doing what you are telling it to do):
manager.addMarkers(batch, 11);
According to the documentation, 11 is the minimum zoom (the first zoom at which the marker will appear).
addMarker(marker:Marker, minZoom:Number, opt_maxZoom:Number)

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 :(