MKMapView won't show user location - ios

I have 2 apps that use MKMapViews and they both previously worked fine, but now they won't show the user's location. Can anyone think of a reason this code wouldn't make a map show the user's blue dot?
mapView.showsUserLocation = YES;
mapView.mapType = MKMapTypeHybrid;
mapView.delegate = self;
I really appreciate any help, I'm stumped right now...

Related

SKMap not showing because of SKCoordinateRegion

I have a strange issue that started happening recently, and i cannot figure out why.
When I initialise my map with this piece of code, everything works perfectly:
_mapView = [[SKMapView alloc] initWithFrame:CGRectMake( 0.0f, 0.0f, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame) )];
[self.view insertSubview:_mapView atIndex:0];
_mapView.settings.rotationEnabled = NO;
_mapView.settings.displayMode = SKMapDisplayMode2D;
[SKRoutingService sharedInstance].mapView = _mapView;
But, when I want to zoom in to a specific region on the map, things go funky and the screen is just blue.
Code:
[self.locationManager startUpdatingLocation];
_lattitude = self.locationManager.location.coordinate.latitude;
_longitude = self.locationManager.location.coordinate.longitude;
SKCoordinateRegion region;
region.center = CLLocationCoordinate2DMake(_latitude, _longitude);
region.zoomLevel = 14;
_mapView.visibleRegion = region;
[self.locationManager stopUpdatingLocation];
Screenshot:
Now, I'd like to mention that the blue screen only appears on the first launch. If i close the app and start it again, the map will be displayed properly (Both in Emulator and on the real device).
I tracked which piece of code is causing this, and it's this one:
_mapView.visibleRegion = region;
How can I fix this?
Probably the location manager has not yet received its position and gives you 0,0 which is somewhere in front of Africas coast. Ocean = blue.
You will need to setup a delegate for the location manager and wait for a positive fix on your position and then display the region in your map. In your code above you immediately request the location after starting the location manager.

Rotating MapView in iOS6 on User Gesture

It seems you cannot rotate the map view using user's two finger gesture anymore. It has been a while since I did any iOS development but pre-ios6 it was automatically enabled.
Is this the case or is it me being ridiculous? It seems to me that its a very basic requirement for developers to be able to allow their users to rotate the map.
Any links to documentation that specifically says we can't rotate or some clarification would be much appreciated.
Try UIRotationGestureRecognizer to rotate map.Following code will help you.
UIRotationGestureRecognizer *rgrr = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:#selector(rotateMap:)];
[mapView addGestureRecognizer:rgrr];//mapView -->your mapview
rgrr.delegate = self;
////////
- (void) rotateMap:(UIRotationGestureRecognizer *)gestureRecognizer{
gestureRecognizer.view.transform = CGAffineTransformRotate(gestureRecognizer.view.transform, gestureRecognizer.rotation);
gestureRecognizer.rotation = 0; }

Remove markers from google maps iOS

I am building an iOS app using storyboards and Google Maps. Using iOS6
My application features the split view navigation as seen in the facebook app
On my left view I am selecting an item in a list which has lat/long cords and showing it on my map on the following method
- (void)viewWillAppear:(BOOL)animated
I would like to remove all markers in this method before I add another one (so only one marker is on the map), is there a way to do this? Below is my code to add a marker to the mapView
Thanks in advance - Jon
- (void)loadView
{
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:poi.lat
longitude:poi.lon
zoom:15];
mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView.myLocationEnabled = YES;
self.view = mapView;
mapView.mapType = kGMSTypeHybrid;
//Allows you to tap a marker and have camera pan to it
mapView.delegate = self;
}
-(void)viewWillAppear:(BOOL)animated
{
GMSMarkerOptions *options = [[GMSMarkerOptions alloc] init];
options.position = CLLocationCoordinate2DMake(poi.lat, poi.lon);
options.title = poi.title;
options.snippet = poi.description;
options.icon = [UIImage imageNamed:#"flag-red.png"];
[mapView addMarkerWithOptions:options];
[mapView animateToLocation:options.position];
[mapView animateToBearing:0];
[mapView animateToViewingAngle:0];
}
To remove all markers
mapView.clear()
To remove a specific marker
myMarker.map = nil
To remove all markers simple do:
[self.mapView clear];
Please refer to the Google Map documentation: Google Maps SDK for iOS
Please refer to the section title "Remove a marker". Always check documentation for such methods.
mapView.clear()
// It will clear all markers from GMSMapView.
To remove a single marker from map.
yourMarkerName.map = nil
To remove all markers from map.
yourMapViewName.clear()
It's a little bit tricky here if you want to remove only one marker among a group of your markers.
let marker = GMSMarker(position: coordinate) //
marker.icon = UIImage(named: "ic_pin_marker")
marker.map = mapView
mapView.selectedMarker = marker // the specific marker you want to remove or modify by set it as selectedMarker on the map.
then you want to remove or modify
mapView.selectedMarker.map = nil //example to remove the marker form the map.
Hopefully useful with your condition.
mapView.clear() is not a good idea .
because The Places SDK for iOS enforces a default limit of 1,000 requests per 24 hour period.(If your app exceeds the limit, the app will start failing. Verify your identity to get 150,000 requests per 24 hour period.)
whit mapView.clear() the requests increase .
the best way is clear each marker and polylines .

how to reduce the time of showing blue circle and point in MKMapView

I use a MKMapView to show my current location , I found that when i am doing nothing ,it will take me about 15+ seconds to see the blue circle and point in the map view ,but if i move the map after the map view is start to locating ,the blue circle and point will show immediately (will dont need 5 seconds now) ,what 's the diffrence between them ? can I short the time to show blue circle in coding ? thanks alot
i create the map
self.runMapView = [[[MKMapView alloc] initWithFrame:self.bounds] autorelease];
self.runMapView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
self.runMapView.showsUserLocation = YES;
runMapView.delegate = self;
and then :
- (void)mapView:(MKMapView *)mapView_ didUpdateUserLocation:(MKUserLocation *)userLocation
{
if (loc2 == nil)//loc 2 is the ivar i used to track my first location
{
if (CLLocationCoordinate2DIsValid(userLocation.location.coordinate))
{
self.loc2 = userLocation.location;
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.location.coordinate, 2000, 2000);
[runMapView setRegion:region];
}
}
}
and i add some polylineview to the map,and when i add the mapview to the view ctrl 's view at start ,the mapview 's alpha is set to 0(because i have a button to decide show or hide mapview),i dont know if the map update location in back can cause this problem?
Create one variable for location manager,
You need to update location just below the mapview initialize like this:
self.runMapView = [[[MKMapView alloc] initWithFrame:self.bounds] autorelease];
self.runMapView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
self.runMapView.showsUserLocation = YES;
self.runMapView.delegate = self;
[self.locationManager startUpdatingLocation];

Map Issue In iOS 6

In iOS 5 this worked fine, and I was under the impression that everything from MKMapKit would continue working in much the same way. However, instead of zooming to my location and adding annotations that I have set up, it just shows North America. I am leaving the annotations out of the code snippet I have, and just putting in the initial code setup.
[mapView setMapType:MKMapTypeSatellite];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];
mapView.delegate = self;
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
region.center.latitude = 32.385325 ;
region.center.longitude = -86.217442;
region.span.longitudeDelta = 0.005f;
region.span.latitudeDelta = 0.005f;
[mapView setRegion:region animated:YES];
Any thoughts on why it is not zooming to where I have it set?
I personally don't suspect an iOS 6 v iOS 5 issue. This code works fine for me in iOS 6. So the problem rests elsewhere.
In short, a problem with the mapView variable seems far more likely. Have you checked to see that mapView is not nil? There are all sorts of simple candidate issues:
Perhaps you manually declared class instance variable for a property (which you should not do ... simply define your property and let the compiler synthesize your instance variable for you, precisely to avoid this sort of possible confusion); or
Perhaps there was a failure to link up the IBOutlet, etc.

Resources