How can I set the zoom point of a Google Map in iOS to be off-center? - google-maps-sdk-ios

I am implementing a Google Maps for iOS SDK map in my app. I have a UISlider that controls the level of zoom in the map. I want to be able to have the map zoom in on a point that is not directly in the center of the map -- and after zooming in, this point should be offset from the center of the map by the same number of pixels as before.
I tried setting mapView.layer.anchorPoint to an off-center point, but if I do that, then it screws up the map drawing and it draws the whole map off-center, leaving black areas.
I tried zooming in on the point itself, but that moves it to the center of the map, which I don't want.
Is there a convenience method for simply telling the SDK to treat a different point other than the direct center, as being the "fulcrum", if you will, of the zooming?

Related

Get static image from Google map for given area

I know that Google Maps provides an API for getting static images:
https://developers.google.com/maps/documentation/static-maps/intro
However that API gets as input a center point, zoom level and output image size.
In my case, I need an image that fits a given area taking as input the NW (top-left) and SE (bottom right) coordinates describing the rectangle of my area. I don't see that option within Google Maps API, so I'm wondering if there is another way to accomplish this.
You can omit the center and zoom parameters if you specify at least one marker. In this case you can show a certain area with a marker.
For example, I have bounds of Barcelona in Spain:
41.320004,2.069526 and 41.469576,2.22801
I can easily calculate the center position of the bounds:
41.39479,2.148768
Now, let's put a marker in the center of bounds and use the visible parameter of Static Maps API to specify NW and SE.
visible (optional) specifies one or more locations that should remain visible on the map, though no markers or other indicators will be displayed. Use this parameter to ensure that certain features or map locations are shown on the Google Static Maps API.
https://maps.googleapis.com/maps/api/staticmap?size=600x400&markers=icon%3Ahttp%3A%2F%2Fwww.google.com%2Fmapfiles%2Farrow.png%7C41.39479%2C2.148768&visible=41.320004%2C2.069526%7C41.469576%2C2.22801&key=api_key
Code snippet
<img src="https://maps.googleapis.com/maps/api/staticmap?size=600x400&markers=icon%3Ahttp%3A%2F%2Fwww.google.com%2Fmapfiles%2Farrow.png%7C41.39479%2C2.148768&visible=41.320004%2C2.069526%7C41.469576%2C2.22801&key=AIzaSyDztlrk_3CnzGHo7CFvLFqE_2bUKEq1JEU&signature=WkICJTRmmI1EgDK2VJI4l9lt3qA=" title="" />
As a result, you have an image with specified area. I think you can even go further if you create a transparent png file for marker icon.
Hope it helps!

Google Maps API v3 - Get bounds of Map using div size, centre and zoom

Given the size of my map div, lat-lng of the centre and the zoom, I want to find out what are the bounds of the map (i.e. the top-left and bottom-right lat-lngs)
The problem is that I need to know this before the map is loaded. Therefore, I cannot simply call map.getBounds to get this information.
How should I calculate this information?

How to translate mercator map coordinates to relative screen coordinates?

I have a database with various map locations (latitude, longitude).
I've been using a map api (e.g. google maps) to plot these locations.
I am now experimenting to see if I can totally remove dependency of map apis and simply replace the map control with an image (an .png image).
Question:
How can I translate the map locations to be displayed properly onto this map image?
More details:
Basically, the map will be a rectangular area (i.e. Div element), where the top-left corner of the rectangle is obviously (0, 0). So basically the map locations will be displayed with respect to this top-left corner.
First off, where are you getting your geocodes from? If they are from Bing or Google Maps then you can only use those coordinates with those map controls. Using this coordinates without the map controls is against the terms of use of these API's. Assuming that these coordinates come from somewhere else you can overlay them on an image by first knowing some information about the image. At a minimium you will need to know two coordinates on the image and their relative pixel locations. From that you can then determine the scale and top left coordinate of the image. With this you can then fairly accurately position coordinates on the image using a lot of math. You can find a lot of useful math for this here: http://msdn.microsoft.com/en-us/library/bb259689.aspx I've writing a few blog posts on this a while back which you can find here: http://rbrundritt.wordpress.com/2008/10/25/ve-imagery-service-and-custom-icons/
If these coordinates come from Bing Maps you can easily display them on a map image using the Bing Maps Imagery Service: http://msdn.microsoft.com/en-us/library/ff701724.aspx

Bing Maps vs Google Maps -> markers are in different places

I've made 2 maps, one with Bing Maps and one with Google Maps.
They both pull from the same data file to put a bunch of pins on the map.
However the pins on the Bing map look like they are offset too far north and so not in the right place.
see
http://upstairsweb.com/examples/bingmap.html
vs
http://upstairsweb.com/examples/googlemap.html
The problem is with the icon you're using - the PNG file at http://upstairsweb.com/examples/SmallRedMapPin.png itself is 16px x 18px is size, but the visible part of the pushpin is only drawn in the top left hand corner of the image. Bing Maps by default anchors a pushpin icon at the bottom centre of the map image, but because of the lop-sided transparent area that will make the icon appear to be too far up and to the left. I don't know how Google Maps anchors an icon when you haven't specified an explicit anchor point - perhaps it just hard codes an anchor that, by chance, happens to line up with your points.
Either way, I'd suggest you first trim your image to get rid of the extraneous transparent area around the outside and/or explicitly set the anchor point in the PushpinOptions at which the icon should be placed relative to the point it describes: http://msdn.microsoft.com/en-us/library/gg427629.aspx

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