Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom location on iOS Emulator fails without updating the Info.plist file #210

Open
FireJuun opened this issue Nov 7, 2024 · 3 comments
Assignees
Labels
priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@FireJuun
Copy link

FireJuun commented Nov 7, 2024

In testing with the example app on an iOS simulator with a custom location, I am unable to consistently get the app to initialize its user location. Using this with one of the default locations in Simulator is working as intended, however.

I think I have a fix for this as well, but I'm curious if others are able to recreate this issue.

Environment details

  1. Flutter version 3.24.3, stable channel
  2. macOS 14.6.1 23G93 darwin-arm64, locale en-US
  3. google_navigation_flutter: ^0.3.0

Steps to reproduce

  1. Add a .env/development.env file with MAPS_API_KEY=[[YOUR_API_KEY]]
Default Location (Working)
  1. On Apple Simulator, go to Features -> Location -> Apple
  2. Run example app using --dart-define-from-file .env/development.env
  3. This works as intended, showing the correct location (in this case, Apple's headquarters).
Custom Location -- FAILING
  1. On Apple Simulator, go to Features -> Location -> Custom Location and input latitude -33.852, longitude 151.211 (using this example).
  2. Run example app using --dart-define-from-file .env/development.env
  3. The app will attempt to load user location, but fails and defaults to MIT.
  4. You cannot add any waypoints or start navigation.
Custom Location -- FIX
  1. Add the following lines to your Info.plist file

info.plist

	...
	<key>NSAppTransportSecurity</key> <dict>
	<key>NSAllowsArbitraryLoads</key><true/> </dict>
	...
  1. Run the app with the same settings as Failing Test.
  2. The app will now load Sydney as originally intended.
@FireJuun FireJuun added triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Nov 7, 2024
FireJuun added a commit to FireJuun/nav_stemi that referenced this issue Nov 7, 2024
Otherwise, custom location fails to work properly and may crash the app
@jokerttu jokerttu added priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. and removed triage me I really want to be triaged. labels Nov 11, 2024
@jokerttu
Copy link
Contributor

Hi @FireJuun,

Thanks for reporting this and sharing the suggestion.

While setting NSAllowsArbitraryLoads to true can indeed resolve network-related issues, it is generally discouraged because it disables secure HTTPS connections for all network requests, potentially exposing data to interception or tampering (Apple's recommendation).

We're investigating alternative solutions that offer a secure yet effective way to address this problem. We'll keep you updated on any safer workarounds or fixes as we progress.

Thanks again for helping us improve the SDK!

@FireJuun
Copy link
Author

Looking forward to a safer workaround. Appreciate the effort here.

@jokerttu
Copy link
Contributor

@FireJuun,

I was not able to see any effect from setting NSAllowsArbitraryLoads to true, as this issue does not appear to be network-related.

The reason custom locations don’t work as expected, while default simulated locations do, is due to how location updates are handled. With a custom location, the iOS simulator does not trigger continuous location updates, so the app cannot detect any change. In contrast, default simulated locations provide continuous updates, allowing the app to reliably detect the user’s location when the navigation page opens. This limitation should not occur on physical devices, where location services provide continuous updates.

Additionally, there’s a bug in the example app itself:

_userLocation = await _navigationController?.getMyLocation() ?? cameraLocationMIT;

In this line, _navigationController is always null, causing cameraLocationMIT to be used each time if location is not reported by onRoadSnappedLocationUpdatedEvent on time.
As onRoadSnappedLocationUpdatedEvent event is never fired with a custom location in the iOS emulator, the location doesn’t update after initialization.

We’re exploring the best approach to tackle this, potentially by exposing the location API directly within the plugin. Additionally, developers can use the location package to fetch the current user location for map initialization.

Note that GoogleMap.myLocation is deprecated on Google Maps SDK for Android, and therefore for example app purposes, solution to fetch current location would be beneficial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

3 participants