Reputation: 22846
I got stuck on this. I hope someone can give me the right input!
I'm showing points of interest (GMSMarkers) using a GMSMapview.
At the moment I'm just centering the map on the current POI coordinate using this code (DEFAULT_ZOOM is 15.f):
GMSCameraPosition *newPosition =
[GMSCameraPosition cameraWithLatitude:activePOI.coordinate.latitude
longitude:activePOI.coordinate.longitude
zoom:DEFAULT_ZOOM
bearing:0. //True north
viewingAngle:0.]; //Facing down
[self.mapView animateToCameraPosition:newPosition];
I've tried using GMSCoordinateBounds to display both POI and user locations, with this code:
GMSCoordinateBounds *cb =
[[GMSCoordinateBounds alloc] initWithCoordinate:activePOI.coordinate
coordinate:user.coordinate];
[GMSCameraUpdate fitBounds:cb];
It works pretty well, but both locations are displayed at the corners of the map.
I need to display the POI at the centre, but at the same time display the user location.
Any idea on how to achieve this?
Cheers.
Upvotes: 4
Views: 1592
Reputation: 31745
To display the POI in the centre, and the user location at an edge of the map, you should derive a third location point mirroring the relative distance of user llc from the POI on the other side of the POI.
if we are allowed to ignore the earth's curvature this is simple vector addition
I.e.
loc3 = poiLoc + (poiLoc - userLoc)
= 2*poiLoc - userLoc;
Then your map rect is defined by the userLoc and loc3.
Upvotes: 1