Mapkit and userTrackingMode - ios

I have a question about MapKit. I set the userTrackingMode property to move the map according to the user position update.
[_mapView setUserTrackingMode:MKUserTrackingModeFollowWithHeading animated:YES];
Is there a way to be alerted when you exit from this mode?

From the Apple Docs on MKMapViewDelegate Protocol:
mapView:didChangeUserTrackingMode:animated:
Tells the delegate that the user tracking mode changed.
(void)mapView:(MKMapView *)mapView didChangeUserTrackingMode:(MKUserTrackingMode)mode animated:(BOOL)animated

Related

Updating GMSCameraPosition on GMSMapView position isn't working

I have an app that has a map with a lot of markers on it, the app notifies the user whenever he approaches one of the markers. I'm using Google Maps iOS SDK for the map, that's mean I use GMSMapView for the map view (mapView).
I want that when the user opens the app via a notification (tap on a notification) the map's camera will automatically be pointing to the notification's marker.
I've tried to do it like this:
AppDelegate.m:
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
NSString *markerIdentifier=[[notification userInfo] objectForKey:#"markerIdentifier"];
GMSMarker *marker=[self markerForIdentifier:markerIdentifier];
[self.aroundersVC.mapView setSelectedMarker:storeMarker];
//Important part:
[self.aroundersVC animateMapToMarkerPosition:storeMarker];
}
AroundersViewController:
-(void)animateMapToMarkerPosition:(GMSMarker*)marker
{
GMSCameraPosition *currentLocationCameraPosition=[GMSCameraPosition cameraWithLatitude:marker.position.latitude longitude:marker.position.longitude zoom:16];
[self.mapView animateToCameraPosition:currentLocationCameraPosition];
}
But it's not working for some reason, anyone knows why?
Thanks!
Use GMSMapview delegate
-(void)mapView:(GMSMapView *)mapView didChangeCameraPosition:(GMSCameraPosition *)position
{
// Do your stuff here
}
This should solve your problem.

mapView: didTapMarker isn't selecting a marker

I have a GMSMapView with a lot of markers, every marker represents one store of my client, every time the user approaches to one of the markers (to one of the stores) he gets a notification with the address of the store.
I want that when the user taps on a notification (opens the app via notification) the marker will be presented on the map (already selected).
Note: the marker is a property for every Store object, the UILocalNotification stores the Store object's identifier and that's how I find the correct store.
Note 2: I'm working with Google Maps iOS SDK.
I've tried to do it like this:
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
NSString *storeIdentifier=[[notification userInfo] objectForKey:#"storeIdentifier"];
Store *notificationsStore=[self.monitorLocationVC storeForIdentifier:storeIdentifier];
[self.myVC mapView:self.myVC.mapView didTapMarker:notificationsStore.marker];
}
For some reason, the marker isn't being selected when the user opens the app.
I've override mapView: didTapMarker: on myVC.m like that:
-(BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker
{
return NO;
}
didTapMarker is on GMSMapViewDelegate, it's called by the map to notify your code that the marker has been tapped. It doesn't tap the marker.
You can however set selectedMarker on the map view, to cause that marker to be selected, and to show its info window (if it has one). For example:
self.myVC.mapView.selectedMarker = notificationsStore.marker;
See here for more examples: How to show a Info window in iOS Google maps without tapping on Marker?
-(BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker
{
viewIwant.hidden=NO;
//or any nib you want
return YES;
}

iOS: How to find user location without using Location Services?

Is there any alternative to get User location and do GeoFence rather than using Location Services in iOS. I am asking this because, when we enable Location Services, battery consumption is too high. That's why I am looking for an alternative. What can I try?
If you are using map then, no need to implement location service code to capture current location, set YES to showUserLocation property of MKMapView
[self.mapView setShowsUserLocation:YES]; and implement its delegate method:
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
`
[self.mapView setShowsUserLocation:YES];
[self.mapView setDelegate:self];
[self.mapView setMapType:MKMapTypeStandard];
[self.view addSubview:self.mapView];
[self.view bringSubviewToFront:self.viewLiveDrive];`
delegate :
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation{
NSLog(#"Location Current : %# ",userLocation.location);
[self.mapView setCenterCoordinate:userLocation.location.coordinate animated:YES];
}
Now you can enjoy with current location :)

Drop Pin on Map with Direction Indicator?

We are developing IOS app. Where user can drop pin (Car, Bus etc) on map and define direction (angle) as well. I know how to drop pin but What I need to do for direction angle?
Here are details of my problem. As you can see a pin dropped at may. User can set direction to any angle with his fingers. Like user rotate photo. I need to show pin to other user app users to with exact direction angle. What I need to persist for that at central database or web API end that can be used to place that pin on other user's app.
CLLocationManagerDelegate protocol has a method called - (void)locationManager:didUpdateHeading: in which you can get a hold on users heading aka direction.
Sample:
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
CLLocationDirection direction = newHeading.magneticHeading;
}
NOTE: for this method to be called, you have to call CLLocationManager's instance method - (void)startUpdatingHeading. Like this:
[self.locationManager startUpdatingHeading];
Then if you have a custom view for MKUserLocation annotation you can rotate it based on previously received direction in above method.
Sample:
- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[MKUserLocation class]])
{
// rotated custom view code
}
}

didUpdateUserLocation not getting called re loading the view

I have a mapViewController (in a Navigation Controller). When I open it for the first time, after viewDidLoad, - (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation gets called.
When I go back to the previous viewController and come again to the mapViewController, the didUpdateUserLocation delegate is not being called, hence my annotations are not getting shown.
Please help me in finding the solution to the problem. Thank you.
If you want the map view to continue to track the user’s location and update it periodically, you should set MapView showsUserLocation to YES (the default value is NO).
Try
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
...
[mapView setShowsUserLocation: YES];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
...
[mapView setShowsUserLocation: NO];
}
Apple Doc: http://developer.apple.com/library/ios/#DOCUMENTATION/MapKit/Reference/MKMapView_Class/MKMapView/MKMapView.html
Call this method in - view will appear method of same class
[locationManager startUpdatingLocation];

Resources