21

I'm testing an iOS app with the simulator in xCode 5.x. The root view is a UIWebView that loads an external URL. The external page requests geolocation information, but I cannot get it to work in the simulator. The prompt appears to share location info, but the external page is unable to receive them.

  • I've tried setting a custom location in Debug > Location... but nothing changes.
  • I've tried multiple devices in the simulator, such as iPhone 3.5 and iPad.
  • If I load the app in an actual device, it works fine.

What am I missing?

-e

emersonthis
  • 32,822
  • 59
  • 210
  • 375

9 Answers9

19

+1 to @Farhan for a helpful tip. Here's what solved my problem:

There are two places where simulator location gets set:

  • The Scheme (see Farhan's answer).
  • In the Simulator under Debug > Location

I played with the Default Location setting in the scheme and it didn't work. Mine is currently set to "None" which is unclear as to whether that means there is no location data provided or whether it defaults to the location of the host machine.

In the simulator under Debug > Location, it was also set to none. I tried using some of the presets, but it still didn't work. What eventually made it start working for me is I changed it to "Custom location" and entered the latitude and longitude of where I am located. Only then did it start working correctly.

This post has some helpful screenshots of what I'm describing.

This is a handy tool for getting latitude and longitude.

Update The solution I described above still works, but in the project I'm currently working on it doesn't seem to retain the settings, so I have to keep re-selecting my custom location. This gets tedious, so I created a new preset location using gpx file. Turns out this is really easy. Just use this tool to generate the file and download it. Then when you edit the schema, under Default Location, choose the "Add GPX file to project..." (and select the file you downloaded). That's it. For whatever reason, this setting does seem to get remembered when I re-run the simulator.

Community
  • 1
  • 1
emersonthis
  • 32,822
  • 59
  • 210
  • 375
  • 3
    GPX does help (simulator remembers lat/lng with decimal precision), but my position still not shown on the map. Only way to make it work: right after first simulator start select Debug > Location > Apple, the blue dot will appear, and then Debug > Location > Custom Location and then enter (your correct location will be remembered thanks to GPX file). I guess you have to show the simulator where is home first ;) – Christophe Fondacci Mar 28 '15 at 18:52
  • 1
    Omg... Does anyone know the reason for what @ChristopheFondacci described? I had the same.... – Fr4nc3sc0NL Feb 17 '16 at 12:10
18

You might need to enable it for your specific build. To do that.

In your Xcode go to Product > Scheme > Edit Scheme... 2 - In the Run projectName/ Debug

Select "Run XXXX.app / Debug" > Select "Allow Location Simulation" and select a default location.

Farhan Patel
  • 506
  • 3
  • 7
  • 2
    I checked and "Allow Location Simulation" was already selected with a value of "none". I tried changing to a default location and it still didn't work. – emersonthis Jul 20 '14 at 20:52
  • I can confirm, for me, changing the Location Simulation from None to another one worked for me. Thanks. – Ben Butterworth Dec 27 '19 at 23:51
14

I had the same issue - try this:

Check your Location Settings in the Simulator. Press CMD-Shift-H to exit app, go to Settings->Privacy and select 'While Using the App'. You also need to have set NSLocationWhenInUseUsageDescription key in Info.plist.

Ayushi Jha
  • 4,003
  • 3
  • 26
  • 43
Erlend
  • 1,711
  • 1
  • 22
  • 25
9

To use custom location (adding your own lat/lon coordinates), with the simulator selected, go to the options at top and select 'Features' option

Tap simulator then select these options from the tool bar

Once you select the 'Customer Location' option you can enter your Lon lat details here.

Enter coordinates here

Voila!

Jim Tierney
  • 4,078
  • 3
  • 27
  • 48
2

Delete app from simulator Set coordinates from Debug/Location/Custom Location After Hardware/Reboot simulator

erdikanik
  • 674
  • 9
  • 11
2

If you are still faced with this issue, note that it's caused by a bug in the iOS simulator, I had already updated the custom location in the "Features > Location > Custom location..." as seen in Jim Tierney's answer but when I restarted the app, the simulator doesn't take the new custom location into consideration.

To resolve this, simply open the "Maps" app on the simulator, and make sure it's showing the custom location you selected by tapping on the location icon at the top right.

Minimize it to the background, reopen your app, stop the app and start the app, now the location would show you the expected result.

Kingston Fortune
  • 905
  • 8
  • 17
1

Xcode supports GPX files but it is important to note that the GPX file needs to contain waypoints. Tracepoints don't work, so make sure to only use "wpt" tags in your GPX.

Karsten
  • 2,772
  • 17
  • 22
0

I am also facing the same issue. The location package worked fine on Android, but on iOS devices, it didn't get the location information. So I solve this by changing the location from Simulator Settings.

Solution:

From Simulation Bar > Features > Location > Apple (Select this)

This solves my issue !!

Now I can get location data.

Md. Al-Amin
  • 690
  • 3
  • 13
-1

For me, the problem was that "Debug Executable" wasn't checked on the scheme I was running. Once I enabled this, everything started working normally again with the location simulation.

Andrew K
  • 1,571
  • 1
  • 17
  • 25