dpa99c / phonegap-launch-navigator

Phonegap/Cordova plugin which launches native route navigation apps for Android, iOS and Windows
369 stars 131 forks source link

Unable to geocode destination address to coordinates: Index 0 out of range [0..0) error (Android) #281

Open ryaa opened 1 week ago

ryaa commented 1 week ago

Bug report

CHECKLIST

I could not build/run the Ionic4Example using the provided instructions because npm install fails with the below error

alexryltsov@Alexs-MacBook-Pro-2 Ionic4Example % npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: Ionic4Example@0.0.1
npm ERR! Found: rxjs@6.3.3
npm ERR! node_modules/rxjs
npm ERR!   rxjs@"~6.3.3" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer rxjs@"^5.5.0 || ^6.5.0" from @ionic-native/core@5.36.0
npm ERR! node_modules/@ionic-native/core
npm ERR!   @ionic-native/core@"^5.0.0" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! 
npm ERR! 
npm ERR! For a full report see:
npm ERR! /Users/alexryltsov/.npm/_logs/2024-11-07T15_14_01_315Z-eresolve-report.txt

npm ERR! A complete log of this run can be found in: /Users/alexryltsov/.npm/_logs/2024-11-07T15_14_01_315Z-debug-0.log

Current behavior: When on Android platform the navigate method is invoked, and the user chooses Google Maps mapping app, the app tries to geocoder the address to lat/lng. However, if this address can not be geocoded (for example, the address is unknown city unknown street unknown house which invokes google maps geocoder using this URL https://maps.google.com/maps/api/geocode/json?address=unknown city unknown street unknown house&sensor=false&key=<API_KEY>) and the google service returns the below response

{
   "results" : [],
   "status" : "ZERO_RESULTS"
}

the app fails with the error Unable to geocode destination address to coordinates: Index 0 out of range [0..0 because it always expect the results array to contain the first element - see https://github.com/dpa99c/phonegap-launch-navigator/blob/master/src/android/lib/LaunchNavigator.java#L1704

Expected behavior: No error occurs when address can not be geocoded

Steps to reproduce: See above

Screenshots N/A

Environment information

alexryltsov@Alexs-MacBook-Pro-2 bugfix-479-unable-to-geocode-destination-address-to-coordinates-index-0-out-of-range-00 % ionic info

Ionic:

   Ionic CLI                     : 7.2.0 (/Users/alexryltsov/.nvm/versions/node/v20.11.1/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 8.1.0
   @angular-devkit/build-angular : 17.3.6
   @angular-devkit/schematics    : 17.3.6
   @angular/cli                  : 17.3.6
   @ionic/angular-toolkit        : 11.0.1

Capacitor:

   Capacitor CLI      : 6.0.0
   @capacitor/android : 6.0.0
   @capacitor/core    : 6.0.0
   @capacitor/ios     : 6.0.0

Utility:

   cordova-res : not installed globally
   native-run  : 2.0.1

System:

   NodeJS : v20.11.1 (/Users/alexryltsov/.nvm/versions/node/v20.11.1/bin/node)
   npm    : 10.5.0
   OS     : macOS Unknown

Related code:

            const options: LaunchNavigatorOptions = {};
            if (this.platform.is('android')) {
                options.launchModeGoogleMaps = window.launchnavigator.LAUNCH_MODE.GEO;
            }
            try {
                await this.launchNavigator.navigate("unknown city unknown street unknown house", options);
            } catch (error) {
            }

Console output N/A

Other information: The plugin should be able to handle the use case when geocoding returns no result

ryaa commented 6 days ago

The required fix has been provided in this PR https://github.com/dpa99c/phonegap-launch-navigator/pull/282