googlemaps / flutter-navigation-sdk

Google Navigation for Flutter plugin (Beta)
https://pub.dev/packages/google_navigation_flutter
Apache License 2.0
24 stars 10 forks source link

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

Open FireJuun opened 1 week ago

FireJuun commented 1 week ago

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.
jokerttu commented 3 days ago

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 commented 3 days ago

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

jokerttu commented 2 days ago

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