Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Simulator location not working

Tags:

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

like image 493
emersonthis Avatar asked Jul 19 '14 16:07

emersonthis


People also ask

How do I turn on location on iPhone simulator?

in iOS Simulator menu, go to Debug -> Location -> Custom Location. There you can set the latitude and longitude and test the app accordingly.

How do you mock locations in Simulation?

settings> system > developer options Find the option select mock location app Then select the app you downloaded from step 1.

How do you simulate a location?

If you're making a route, tap-and-hold on the map to drop place markers. Use the play button on the bottom corner of the map to enable the fake GPS setting. You can close the app and open Google Maps or another location app to see if your GPS location has been spoofed.

How do I simulate a location on Apple Maps?

Step 11: When the restore is complete, open the Maps app on your iPhone and select the new location that you would like to use. Tap at the bottom of the screen to get more information about the new location and then select “Simulate Location” to begin using the new location.


1 Answers

+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.

like image 186
emersonthis Avatar answered Oct 04 '22 00:10

emersonthis