Google maps ios api using user's location in fitbounds - ios

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.

Related

Location updates issue for iOS 7

I'm developing an iOS map application, so it's essential to receive location data consistently.
What is happening now is that the system allows the to app load the map and that's it!
The location getting instruction seems to freeze, even the network traffic indicator at the top bar disappears. Simply when I go to Settings->Privacy->Location Updates, switch off location updates for my app and then switch it back on. The map loads the current location.
What could be the possible causes to this?, please advice.
Use:
[_mapView setUserTrackingMode:MKUserTrackingModeFollow animated:YES];
This will smoothly follow the users current location. If you drag the map it will even set the tracking mode back to MKUserTrackingModeNone which is usually the behaviour you want.

Location manager icon still displayed even when I call stopUpdatingLocation

Even though I called stopUpdatingLocation on my location manager, the location manager icon is still on the top right of my iPhone. Why hasn't it stopped?
There are several reasons why the location arrow on your phone may still be on even after calling stopUpdatingLocation.
For one, another app on your phone may currently be using your location.
Another possibility is that you enabled significant location change monitoring using the startMonitoringSignificantLocationChanges method but forgot to turn this off using the stopMonitoringSignificantLocationChanges method. Apps that are monitoring significant location changes will display a solid arrow in the status bar in the same way apps that are using standard location updates do.
Of course it's also possible that you are for whatever reason incorrectly calling stopUpdatingLocation and you actually are still getting location updates from a location manager. To check if this is happening wait several minutes after calling stopUpdatingLocation and go to Settings>Privacy>Location Services and find your app. If there is a solid purple arrow next to your app then your app is indeed currently using location services and something most likely went wrong when calling stopUpdatingLocation. However if there is a solid gray arrow, this just signifies that your app has recently used location services and it's likely that you did correctly stop getting updates. Another way to check if you correctly turned off location updates is by calling your CLLocationManager's location property and checking its timestamp property to make sure that it is not recent. If the timestamp is greater than the timestamp at which you called stopUpdatingLocation then you know something is wrong.
The icon you see at the top is not locationManager, is the location service of the device. If you deactivate in settings no longer appears.

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.

CLLocationManager default coordinate values

I'm learning to develop iOS apps and I try them on simulater only. Now, in my app I use CLLocationManager to get my current location coordinates. But when I run the app no matter where I am I get the same results for all the coordinate values(altitude,longitude,latitude). They do not change even if I move to another location. What I wonder is how does CLLocationManager get values? If it does not work on simulater then where do the values that never change come from? According to the coordinates I guess it's a default value that shows London if no coordinates are available.
Try Resetting the iOS Simulator, erasing all applications and settings.
And when you run CLLocationManager using application, it will probably ask for permission to use location, something like what you would see in you device.
I've been using iOS Simulator, and it gives location of my computer for the simulator all the time. I guess it's affected by your internet connection and IP address. Since many computers don't come with GPS, it's the only way to know the location of the computer.
The simulator always gives the location of Apple headquarters at Cupertino. It does not use computer's gps or location.
Simulator may use skyhook to check your location which is bounded to WiFi hotspot (if it was added with it's coordinates) and if you move in radius of WiFi coverage than your location won't be changed at all.
On the menu bar, go to Debug, then select Location, Custom Location and then you can input coordinates to simulate from. The Simulator will not always provide you the same feedback as a device would.

MapKit Changing the User Location Programmatically

I am trying to make a jogging app which will track where the user ran. It will draw a line on the map where the user is running. My problem is that how to test such an app. Is there anyway I can dynamically change the user location which will fire the didUpdateUserLocation delegate method?
The iOS Simulator supports that feature in the current beta version. You can even simulate a dynamically updating location.

Resources