MapKit/CoreLocation/ShowsUserLocation implementation strategy - ios

I'm implementing a map in one of my apps, the user's location needs to be read and then the map zoomed to current location and then pins added for businesses surrounding the user.
I've got it working to a point but i'm confused as to how to implement the current location stuff.
I tried adding a MKMapView and setting showsUserLocation = YES which in the simulator will always annoyingly place you at Apple's HQ in CA, no good to me for testing!
So, I thought i'd implement CoreLocation which works brilliantly and in the simulator, uses the network/WiFi mapping to figure out that i'm at home and returns lat/long for my home.
However, so far, I can only represent the current location with a MKPinAnnotationView setting it to a green dot. This animates nicely onto my map but what i'd really like though is to have the blue dot as my current location annotation with the circle around it similar to showsUserLocation.
Is there a way in a delegate protocol for MKMapView to intercept how the showsUserLocation = YES internals work to accomplish this? Or, can I reset the co-ordinates that it thinks are right to display my actual location?

The simulator is displaying the Apple's HQ because it doesn't have a GPS chip available.
I'd recommend to test your code on a device and use showUserLocation = YES in order to show the user's current location.
The hack you are trying to do is not recommended.

Related

Google Street View for iOS with device orientation / gyroscope sensor

Is there an easy way to make in iOS Google Street View GMSPanormaView's camera follow the device's orientation via data from its motion sensors?
If not, has anyone already done it and can share a code snippet that takes data from CoreMotion, maybe manipulates it to create GMSPanoramaCamera, and passes it to the GMSPanoramaView with animateToCamera:animationDuration:?
Any relevant Android code would also be useful.
Upon checking the Maps SDK for iOS:Internal: Street View, there is no built-in function/implementation for the device orientation/ gyroscope sensor.
According to Ziem's answer you can try implement this by yourself(create function). He also give pointers to study the following:
Set the camera orientation point of view
Animate the camera movements
Reference:
Blog
Github
Using a site they have successfully create a function that will let you browse the Google streetview panoramas with your smartphone/tablet like you were inside it, just by moving your phone like a window to the world.

MKUserLocation stops updating when map is touched

I am using MKMapView, and has enabled tracking for current location.
mapView.showsUserLocation = true
mapView.setUserTrackingMode(.FollowWithHeading, animated: false)
When i touch or hold the screen it stops updating. Is it any way to prevent this?
I want the map and user location (blue dot) to continue animating.
Edit:
The same "problem" happens if you touch, zoom or pan in the original iOS Maps app.
This is not a problem. This is how it is supposed to work. In the iOS maps app you can toggle between the three modes (track location, track location and heading, no tracking).
When you have it in either of the tracking modes and the user moves the map the tracking is changed to no tracking.
This is so that you are not overriding what the user has done. Note, it will still keep the blue marker updated for the user's location it just won't track them.
If it didn't do this then when the user tries to scroll the map it would keep jumping back to the user location instead of letting them see what they want to see.
You could change this by disabling the user interaction on the map. But I wouldn't try to override this default behaviour. It is a learned behaviour of how the map works in iOS. Changing it will give the user the impression that it is broken.

Google maps ios api using user's location in fitbounds

I am trying to set a bounds between the users location and a selected marker. I can set everything up properly but when I try to use the users location (mapView_.myLocation.coordinate) it says the lat and long are both 0. I did create a button to center the camera on the users location and it gets the lat and long just fine. Does not make any sense to me. Also I don't have a device set up to test so I am using xcodes iOS simulator with a location put into the simulator (is that where my problem is?). Any ideas?
Are you trying to access myLocation.coordinate from loadView or similar, ie when the app first starts up?
Generally when enabling location services the app doesn't receive a location update immediately, it comes through after some delay. So it's possible that myLocation.coordinate won't be valid in loadView, but will have a value set some time later (which is why it works with your button).
You could perhaps listen for changes to myLocation, and then set your bounds when it changes to something.

MKMapView Loads before LocationManager has got user location - cannot set Region to center on user location

I have an iOS app where Im loading a MKMapView as the app starts. I want to set the center of the "MKCoordinateRegion" to be the user latitude/longitude. However, the CLLocation Manager instance does not update the user location until after the MKMapView has loaded.
For now I am hard coding the map center coordinates into the app. But I was wondering if anyone can suggest a better way to handle this situation.
I can think of 2 approaches but Im not a fan of either of them:
1) Stall launching the MKMapView using an activityindicator
2) Launch the MKMapview with the hard coded location and then as soon as the user location is available animate the mapview region to center on that location
Any suggestions?
Store the last known lat/long when you go to background or when app is closed.
On start center map view to last known position.
As soon as location manager sends an updated location, update the map center.
Set the userTrackingMode property of the mapview to MKUserTrackingModeFollow. You don't need a location manager for this, mapView does it for you. When you later want to relocate the map, set the property to MKUserTrackingModeNone, and relocate your map.
Do what Apple does. Start really far zoomed out, maybe put a message on screen "Scanning for location", then when the location information is available zoom in.

iOS : Detect user location when App is back from Background

I have a MKMapView & I use it to display user's current location. It works normal when I first load it in the App. But when I press Home button to put the App to background & call it back from background, the map prompts it is unable to find the user's location.
I was thinking is the MKMapView takes time to search for user's location, and when I call it back from background, it does not have enough time to load the location service ?
iOS5 SDK, xCode 4.3 is used.
If I understand your question correctly, your problem is that when your app resumes (becomes active), mapView.userLocation returns nil. Although I haven't tested this, I suspect it is because the mapView will need some time to relocate the user. You can get around this by adding your logic to the appropriate delegate method instead, which is - (void) mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation, if memory serves me right (you might want to verify that, though).
EDIT: Make sure you test location-related code on a device, since its behaviour might differ from the simulator.

Resources