What is the default coordinate of GMSMapView - ios

I am using Google Maps iOS SDK.
I have installed the pod 'GoogleMaps'.
I have done the instantiation of Google Maps Services with Google API Key in App delegate.
I have created a UIView in storyboard and changed the view's class to GMSMapView and created outlet as mapView.
In viewDidLoad(), if i print mapview's coordinate as below, i get the lat long 51.1789, -1.8264
Can any one let me know if (51.1789, -1.8264) is the default coordinate of GMSMapView

No, (51.1789, -1.8264) are not default coordinate of GMSMapView.
Actually you are calling the mapView.camera which is used to control the camera, which defines how the map is oriented.
& You are try to access the target object which defines the location on the Earth towards which the camera points.
Here
target.latitude returns the equator position (In which Positive values indicate latitudes north of the equator & Negative values indicate latitudes south of the equator).
target.longitude returns meridian position (It Measurements are relative to the zero meridian, with positive values extending east of the meridian and negative values extending west of the meridian).
Here is the visual explanation:
For learn in depth, just follow official documentation iOS >
Maps SDK for iOS

Related

Rotate GMSMapView based on compass

I'm working on an app where manual interaction with map is not allowed. The only way to change the map is as user is moving towards a direction. So if a user rotates the phone rotates and so based on the compass in iPhone the map should rotate automatically rather than user rotating it to the direction by 2 fingers gestures. Here is a picture that clear the idea a little more:
Consider the red dot as my location and as I rotate my phone I want google map to rotate with it. So my question is that how this can be achieved? As there is a method I found [_myMap animateToViewingAngle:45]; after searching but this didn't did what I was looking for.
EDIT I thought of this is there any way we can convert lat and long values to angle?
You can use the course property from the CLLocation and pass it to the animateToBearing method of your GMSMapView. From the documentation:
Swift
var course: CLLocationDirection { get }
Objective-C
#property(readonly, nonatomic) CLLocationDirection course
Discussion
Course values are measured in degrees starting at due north and continuing clockwise around the compass. Thus, north is 0 degrees, east is 90 degrees, south is 180 degrees, and so on. Course values may not be available on all devices. A negative value indicates that the direction is invalid.

Google Map's marker not being displayed properly

The app I'm working on has a map which contains a circle on top that resembles the area that will be searched plus it shows the area in miles on top. In order to calculate the area covered, I need to find the radius of the circle after the map camera has changed (or in Apple maps terms, when the region changes). In order to test that the map is getting the right destination/length of the radius , i'm placing a marker at it's center and a marker at the boundaries of the circle. After that i calculate the radius and continue to calculate the area. I was working with Apple maps first and everything worked fine and now i switched to Google maps in order to use Places API and other API's. In Apple maps the deltaLongtiude and deltaLatitude from the region made it easy to calculate the changes when the region has been changed. In Google maps, they use Camera instead of Region. it has no deltaLatitude/Longitude (correct me if i'm wrong). I'm using the same equation here to calculate the distance using cross multiplication. When i zoom out of the map and drag the map, the center mark is placed correctly however the marker on the boundary is misplaced. Please find the code below of what I'm doing.
In viewDidLoad: i set up the map as follow:
GMSMarker *currentLocation = [GMSMarker markerWithPosition:CLLocationCoordinate2DMake(latitude, longitude)];
currentLocation.map = _map;
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:latitude+0.0075 longitude:longitude zoom:13];
_map.camera = camera;
[_map setMinZoom:1 maxZoom:13];
The 0.0075 is just to adjust the camera properly.
Now in order to view if the markers are placed correctly, i use the following delegate method:
- (void)mapView:(GMSMapView *)mapView didChangeCameraPosition:(GMSCameraPosition *)position{
GMSMarker *currentLocation = [GMSMarker markerWithPosition:CLLocationCoordinate2DMake(position.target.latitude-0.0075, position.target.longitude)];
currentLocation.map = _map;
GMSMarker *currentLocation2 = [GMSMarker markerWithPosition:CLLocationCoordinate2DMake(position.target.latitude-0.0075, position.target.longitude + ((0.0172*position.zoom)/13))];
currentLocation2.map = _map;
}
currentLocation places a marker in the center and currentLocation2 places a marker at the boundary. In order to place the marker correctly in case the user zoomed out, I do a cross multiplication. Since at zoom level 13 the boundary marker should be longitude+0.0172 from the center marker, i multiple 0.0172 by the new zoom level and divide it by 13 and add the value to he longitude. When i run the app and zoom out and drag the map, the boundary marker is misplaced. It's somehow has the same coordinates of the previous zoom level. DO i have to update anything in order to make it work or am i doing anything wrong?
to view more what i'm talking about here are pictures. The first show the map at zoom level 13. As you can see a marker in center and a boundary marker. In the second picture it's at a different zoom level and as you can see the boundary marker stays in same place and doesn't add a new one on the updated camera.

MKMapView show extra zoomed region. How?

I need to show very small area (30x30 meters) on MKMapView. Setting appropriate region or visibleMapRect doesn't work. MapView shows much bigger region.
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([centerLocation coordinate], 30, 30);
[mapView setRegion:region];
It seems with extra small regions MapView corrects with regionThatFits method before update map.
Manually zoom allows displaying such region.
MapKit is not really designed for such high-zoom indoor uses. You may want to check out alternatives such as the open source MapBox iOS SDK, which has been used for indoor applications. In particular iOS 7's iBeacons technology as well may be useful to you for indoor triangulation and higher accuracy than something like GPS, which was neither designed for indoor nor high-zoom use.
According to Apple docs:
When setting a new region, the map may adjust the value in the region
parameter so that it fits the visible area of the map precisely. This
is normal and is done to ensure that the value in the region property
always reflects the visible portion of the map. However, it does mean
that if you get the value of that property right after calling this
method, the returned value may not match the value you set. (You can
use the regionThatFits: method to determine the region that will
actually be set by the map.)
So, when you apply distance, it creates the region which is best fit for your request. It will not be exactly same as what you have requested.
Also, 30*30 meters is very very high zoom level which might not be supported. Hope it will help.

MKMapView - Is there a way to use MKUserTrackingModeFollow with a modified center/focus?

I have a MapView that takes up the full screen and a few elements toward the top of the screen that overlay the map. These top elements potentially cover the blue location marker.
The map is currently tracking fine with MKUserTrackingModeFollow, but I'd like to move the tracking focus down about an inch (obviously the metric will vary by zoom level) to ensure the marker isn't covered. Is there a way to do this with MKUserTrackingModeFollow?
I've considered moving the map with the top elements, but due to design constraints this isn't an option.
Instead of using the userTrackingMode of the MKMapView object to follow the user's location, you could set up a delegate of CLLocationManager to receive location tracking events, and with each location update event you receive, set the center coordinate of the map view, with your vertical offset added to the coordinate value.
You can use the various Map Kit functions and MKMapView methods to convert your offset from some fraction of the map view's bounds.height to a MKMapPoint or CLLocationDistance value.

How to restrict the google map view from panning beyond provided coordinate bounds?

I'm using Google maps sdk in ios.
I want to restrict the user from viewing other states than the states he is allowed to view. The allowed region to view on the map is given as coordinates (FarRight Latitude and Longitude), (Near Left Latitude and Longitude) and the (Center latitude and Longitude).
------X
---X---
X------
X marks the allowed map coordinates on the big map.
When the user pans the map to a coordinate outside this boundary then it has to be panned back to the old location.
But the problem is, In google maps SDK,
- (void)mapView:(GMSMapView*)mapView didChangeCameraPosition:(GMSCameraPosition*)position
The above method gives the position of the visible map coordinate. From the property "Position" we can get only the target center coordinate not the boundar coordinate. How to solve this issue ?
Thanks.

Resources