Setting Maximum Zoom Level kGMSMaxZoomLevel for Google Maps for iOS SDK - google-maps-sdk-ios

I am trying out the iOS Google Maps SDK and notice in GMSCameraPosition.h header file there is reference to kGMSMaxZoomLevel to set the maximum zoom level allowed. I'd like to be able to set this but when #defining a value for that in the implementation, XCode states that there are duplicate symbols when doing so, so won't compile. Can someone point me in the right direction for setting the Minimum and Maximum zoom levels using this new SDK?
Many thanks

I know this is an old post, but just for the sake of completeness I am posting this.
Recent version of google maps SDK features -setMinZoom:maxZoom: which should serve your purpose.
Reference link here.

The kGMSMaxZoomLevel is the maximum value which the SDK supports, ie which you can set when creating a GMSCameraPosition. You can't change its value, to make maps stop at a different zoom level.
You could maybe try listening for [mapView:didChangeCameraPosition:], and then if the camera position is more zoomed in than you'd like, move it back out again. I haven't tried this, so I'm not sure if it would work. It might stutter a bit - ie the user will zoom a bit past the max, you'll set it back, then the user will zoom a bit past again, and so on.

func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition) {
if position.zoom < 10 {
let latitude = mapView.camera.target.latitude
let longitude = mapView.camera.target.longitude
let mapCamera = GMSCameraPosition.camera(withLatitude: latitude, longitude: longitude, zoom: 10)
mapView.camera = mapCamera
}
}

Related

Allow Further Zoom on Google Maps v3 Satellite View

I have some very high resolution aerial imagery that I would like to display over a satellite view base map. My imagery is good enough to generate images up to zoom level 23. However, Google's satellite view only allows zooming in to level 20. I know that I can manually switch the map type to my custom overlay once the user zooms in to level 20 (so only my map type is shown), but then I lose the Google imagery for a full zoom level.
My question is, is there some way to register for an event once the zoom reaches level 20, where the client is attempting to zoom in further but can't? If not, are there other ideas on how I can enable further zooming without losing the Google imagery at level 20?
The only other solution that I can come up with is to create a second custom tile server that simply forwards requests on to the standard Google tile url, but that offers a different min/max zoom. If this idea is the way to go, I would like to get confirmation on that as well. Thanks.
I determined that the simplest solution is to overload the function where the zoom range is changed, using the following incredibly hacky code:
var zoomRangeModifier = googleMap.__proto__.__proto__.__proto__;
var originalSetFunc = zoomRangeModifier.set;
var hijackedSetFunc = function(name, value) {
if (name === 'maxZoom') { // Old API: name === 'zoomRange'
value = 23; // Old API: value.max = 23;
}
originalSetFunc.call(this, name, value);
};
zoomRangeModifier.set = hijackedSetFunc;

Center map between two points WinRT

im trying to center the windows phone map between two points, adjusting center and zoom to make that points visible at the same time.
Im Android and IOS there are functions to do it, as example this is how to do it in Android:
LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(myPos.getPosition());
builder.include(defaultPos.getPosition());
mapa.animateCamera(CameraUpdateFactory.newLatLngBounds(builder.build(), 50));
How can i do the same in WinRT?
Thanks in advance.
If you are targeting Windows Phone 8.1 instead of WinRT (Windows 8/8.1) then you can do the following:
var geoboundingBox = new Windows.Devices.Geolocation.GeoboundingBox(
new BasicGeoposition() { Latitude = 40, Longitude = -90 },
new BasicGeoposition() { Latitude = 45, Longitude = -100 });
map.TrySetViewAsync(new Geopoint(geoboundingBox.Center));
For the Bing Maps WinRT control you can do this in two different ways. The first is to create a LocationRect from the two points. This will create a bounding box for your locations. You can either set the map view to this LocationRect using the SetView method on the map which will center and zoom to these locations, or you can use the Center property of this LocationRect to set the view of the map such that it is centered on these two locations, without zooming into the map. Something like this should work:
var bounds = new LocationRect(new Location(40,-90), new Location(45,-100));
map.SetView(bounds.Center);
Another method requires a bit more calculation but a good option to know if you come across other map controls that don't have an easy solution like the first one I mentioned. This method consists of calculating the center coordinate between the two locations. I have a blog post on how to do this from a vey old version of Bing Maps here: http://rbrundritt.wordpress.com/2008/10/14/calculating-the-midpoint-of-a-line-segment/ The logic can be easily migrated to other programming languages.
It sounds like you are new to developing with Bing Maps in WinRT. I recommend checking out my free ebook on how to create location intelligent Windows Store apps. It goes into a lot of detail on how to create great apps using the Bing Maps control. You can download a copy of it here: http://rbrundritt.wordpress.com/my-book/

Can the google map type be changed to RoadMap when zoomed out?

Google has recently made changes to their maps, it switches to Terrain mode when zoomed out (from zoom level 17 onwards). Is it possible to switch it back or force it to remain in RoadMap mode using the javascript API?
You can not do it. Because Google changed tiles itself, so we cannot do it anything.
Kasheftin has come up to a solution to this as an answer to his question "Auto switch to other mapType on max zoom level in google maps": https://stackoverflow.com/a/18147423/348485

How to reset camera altitude in Google earth

I want to reset the camera position to a much higher position or lesser zoom.
I am looking at the code here:
http://earth-api-samples.googlecode.com/svn/trunk/demos/drive-simulator/index.html
I think it should be done using DS_simulator object, but am not able to find out how.
Any help is appreciated.
You can use the Camera or LookAt to achieve this. Zooming in and out is controlled by the range attribute for a LookAt, and the altitude attribute for a Camera.
Here is a quick example of setting the range using a lookat.
// Get the current view.
var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
// Zoom out to twice the current range.
lookAt.setRange(lookAt.getRange() * 2.0);
// Update the view in Google Earth.
ge.getView().setAbstractView(lookAt);
See this document for more information on controling the view using these two objects.
https://developers.google.com/earth/documentation/camera_control
Also, you can play with a working example here.
http://code.google.com/apis/ajax/playground/?exp=earth#move_camera

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