Problems with current location pin - ios

I'm working on an app that shows a couple of places on the map along with the user's current position.
I have two small problems with it:
First off, I want the current location pin to be the default blue circle, but it shows a green pin just like the other locations.
Second problem, whenever I touch the screen, the current location pin drops again. It just can't seem to be steady like the other ones. It's like it's being called whenever I interact with the app.

Make sure you set your mapView delegate to self...that should fix the pin color. Not sure about your other problem
// in the viewDidLoad
[mapView setDelegate:self];
where "mapView" is defined as "IBOutlet MKMapView *mapView;"

Related

Zoom into current user's location on MapView without restricting scrolling?

I'm using the following code to zoom into my user's current location on a MapView. It works great, however I still want to allow my users to be able to scroll outside of the set region as well (e.g. so that they can see other users on the map). Right now, if my user scrolls outside of the set region, the MapView reverts the user back inside of the set region. How can I execute the below code (zooming into the user's location) while still allowing them to scroll outside of the set region?
MapViewController.m
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate, 1300, 1300);
[self.mapView setRegion:[self.mapView regionThatFits:region] animated:YES];
}
I wrote a short an easy app that will show the user location and also keeps track of the user location. The app will focus on the user location and will keep the user location centered as long as you don't scroll the map view.
As soon as you start scrolling the map view moves away from the user location and stays that way, since the map view is not automatically moving back. To enable you to get back to the user location, I added a button called "focus" that centers the map view back to the user location and makes the map again focus on the user location until you start scrolling away again.
The app is actually quite simple, it uses the two properties in MKMapView:
var showUserLocation: Bool {get set}
var userTrackingMode: MKUserTrackingMode {get set}
You can, of course, zoom further in to the user location by setting the region, but that is easily done with the setRegion(_:animated:).
You can find the code on Github here and download it to see how it works. You can easily test this with the simulator.
Let me know if this helps.

ios: disable mapView update after adding annotations and calling mapView.showAnnotations()

I have just build an swift app that takes data+coords from dynamoDB and puts it onto the ios mapkit. There are two sets of coords: one for current user location and one from dynamoDB. I want these coords to be able to update inside the map, but do not want the actual mapView to zoom and move at all (only the user can zoom and move).
I have achieved everything above except the last part. Currently whenever the annotations are added and mapView.showAnnotations is called, the mapView zooms and moves to enclose the annotations. How do I disable this?
To show mapView annotations without updating mapView zoom and constraints, use addAnnotations() rather than showAnnotations.
I am guessing that you used code from online (which we all do, no worries) and that your code looked something like this. If I am right, then you likely have a line somewhere like this:
[map setRegion:scaledRegion animated:YES];
That line is the issue. You need to use some sort of boolean to make it so that it only happens once. So you could set the boolean has_mapped = false until you have called your update method once, at which point it = true. Then change your line to say something like,
if (has_mapped)
[map setRegion:scaledRegion animated:YES];

RMPath jumps on [mapView moveToLatLong:] call

I am using Route-Me library to display a map on iOS. And RMPath class to display route path on the map. But the route path jumps on [mapView moveToLatLong:] call.
It happens because the map changes it's position on the screen but the route path doesn't change it at the same moment. It changes position on the screen with little delay. But if I scroll map with gestures there is no this issue.
Is it any possibility to fix the issue?

snapshot/screenshot with MKMapview

I am trying to make a snapshot from a view with a MKMapview to provide a springboard like folder animation when the user selects an annotation.
The official way to make a snapshot of the current window is presented here. This works fine (though quite slow) unless the mapview is not zoomed in too much and has a "regionThatFits" set. The map & the marker make an unmatched "jump" to the left and the gridlines of the mapview are visible:
Before screenshot:
After screenshot:
I suppose it has something to do with the tiled parts of the map but I don't know how to prevent that behaviour.
Any thoughts?

A better way to mark location on a map

I'm making an iOS app, where I want users to mark locations on a regular basis on a map. The default way to mark location in iOS is to drop a pin either at the center of the map or where the user holds a touch (using the gesture recognizer).
Then to mark the pin to the desired location ACCURATELY, the user holds the pin and can drop it again. If you have done this on an iOS maps app, you will know it is hard to mark a location ACCURATELY, in this manner. It looks cool, but takes some trial and error in my opinion.
If I can help it, I want to make this process smoother and more obvious is my app.
So is there any other way for the user to mark a location on a map, without doing the default pin drag-drop? Any Suggestions welcome :-)
Just an idea... instead of moving the pin, you could move the map with the finger, and keep the pin always in the middle of the mapView (maybe marked with a crosshair or something). Then you can get the coordinates of the Pin using the "center" method of the mapView. That way you don't cover the pin / crosshair with your finger.
I recommend you have a look at the Maps app again. When you hold down your finger on a dropped pin, notice the location of bottom of the pin on the map. The pin actually drops in this exact location, after doing a quick bounce. The pin also sits about 20 above the users finger.
While it's not the most obvious, it's very accurate in my opinion. Enough to query the Geocoder API for an address, or just get coordinates. Keep in mind the GPS has an accuracy of 5-10 meters at the most. Zooming in will allow the user to go even more accurate.
But if this solutions isn't what you want, I'd overlay a point in the centre of the map and make sure it doesn't respond to touches, making it possible to move around the map underneath this point. When touched end, then drop a pin in the middle of the map where the point is. If touches begin again, pop out the pin from the map. I don't think a pin that's already on the map staying in place while the map moves independently will look good.

Resources