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

Unable to fetch Location on VIVO Devices #255

Closed
enfield09 opened this issue Nov 21, 2022 · 70 comments
Closed

Unable to fetch Location on VIVO Devices #255

enfield09 opened this issue Nov 21, 2022 · 70 comments

Comments

@enfield09
Copy link

Unable to fetch Location on VIVO Devices like V15 Pro and other models with Android Version 12. I am using cordova geoLocation plugin version 4.1.0. Please help me to Fix this issue. Thanks in Advance.

@vudq
Copy link

vudq commented Nov 21, 2022

I have the same issue. Did anyone already find a solution?
8536c9957bdba285fbca

@enfield09
Copy link
Author

did you find any solution?

@deepakpapney
Copy link

facing the same issue from the last 2-3 days, Does anyone knows how to fix it? previously it was working fine.?????

@breautek
Copy link
Contributor

Most likely will be fixed when #250 is fully released.

If you could test the development version of the plugin and provide feedback, that would be great.

cordova plugin remove cordova-plugin-geolocation
cordova plugin add https://github.com/apache/cordova-plugin-geolocation.git

Just a reminder that development versions haven't been voted on or tested for release, so the build should not be used in production environments.

@atmanegara
Copy link

atmanegara commented Nov 21, 2022

yes till now (already 1 week), i have the same problem, not only vivo devices but also oppo,
I got the information from the user, after updating the system on the device, between October and November, the geolocation can't be used anymore (request timeout), (GPS/or Google maps work fine), debugging via Android studio also doesn't show any problems, but samsung or xiaomi devices are fine on android 12

@vudq
Copy link

vudq commented Nov 22, 2022

Most likely will be fixed when #250 is fully released.

If you could test the development version of the plugin and provide feedback, that would be great.

cordova plugin remove cordova-plugin-geolocation
cordova plugin add https://github.com/apache/cordova-plugin-geolocation.git

Just a reminder that development versions haven't been voted on or tested for release, so the build should not be used in production environments.

We used the plugin from github just like you indicated but still can't get the location.

@atmanegara
Copy link

Most likely will be fixed when #250 is fully released.

If you could test the development version of the plugin and provide feedback, that would be great.

cordova plugin remove cordova-plugin-geolocation
cordova plugin add https://github.com/apache/cordova-plugin-geolocation.git

Just a reminder that development versions haven't been voted on or tested for release, so the build should not be used in production environments.

yes, we have installed this plugin, the location application is still not found,
but if via the browser on the oppo/vivo device it works fine,
the general syntax we use

const options = {
      enableHighAccuracy: true,
      timeout: 5000,
      maxAge: 0
    };
    
    function success(pos) {
      const crd = pos. coords;
    
      console. log('Your current position is:');
      console. log(`Latitude : ${crd. latitude}`);
      console. log(`Longitude: ${crd. longitude}`);
      console. log(`More or less ${crd. accuracy} meters.`);
    }
    
    function error(err) {
      console. warn(`ERROR(${err. code}): ${err. message}`);
    }
    
    navigator. geolocation. getCurrentPosition(success, error, options);

is there a problem in webview cordova for vivo/oppo devices?

@prabusharan
Copy link

facing the same issue from the last 2-3 days, Does anyone knows how to fix it? previously it was working fine.?????

@utk4rsh92
Copy link

facing geolocation fetch problem from past 3-4 days for Vivo device Funtouch(Android 12) OS, anyone have solution for this?

@mobiliseapplabllp
Copy link

i am also facing the same issue last 2-3 days previously it was working fine.
one plus nord can't get location i already update plugin but problem not resolved
samsung, realme, redmi working fine but one plus nord and many client phone can't get access location

"cordova-plugin-geolocation": "^4.1.0",
"@ionic-native/geolocation": "^5.36.0",

@mobiliseapplabllp
Copy link

facing geolocation fetch problem from past 3-4 days for Vivo device Funtouch(Android 12) OS, anyone have solution for this?

same problem did you find the solution

@breautek
Copy link
Contributor

is there a problem in webview cordova for vivo/oppo devices?

Here is what I know and don't know...

I do not know if there are device-specific issues. There is an issue on Android 12 devices regarding geolocation via the webview, which is still an open issue. This is a webview bug, not something that Cordova can deal with directly. The bug has to do with attempting to request strictly coarse location. Effectively with this bug, enableHighAccuracy must be true and the application must have the FINE location permission.

#250 works around that issue by asserting that fine location is always enabled on Android 12+ devices, additionally it also treats both permission levels independent as now recommended by Android 12 location changes.

Now, based on the comments so far, it seems like whatever has happened in the last 3-4 days as many pointed out so... this does not seem to be related to that issue. Cordova hasn't released anything that would have broken this runtime (#250 have been merged in, but it isn't released). Presumably these developers also haven't made any updates to their app that would have caused a difference in their geolocation code. With these assumptions, the only thing that can update and cause difference in behaviour in their app is the system webview, which was updated on Nov 14. Giving time to publish and end users to update their device with the latest version (107.0.5304.105), the timeline probably fits.

What I would suggest is attempting to reproduce the issue with a stripped down sample application and raise an issue with Google Chromium team. They will expect an APK and the full source code of the reproduction app.

@jubinpatel
Copy link

jubinpatel commented Nov 23, 2022

We are also strugling with same issue majorly with OPPO, VIVO, REDMI, MI devices Also for few rare cases in OLD LG/MOTO smartphones.
One thing I have observed most of them having WEBVIEW of 107.X.X version.

Onyone If you have found existing ticket or reported to Google, please share link here for refrence.

EDIT: few Android 9+ device also reported same issue, and strage behavior, sometime its working, sometimes not. BUT for OPPO/VIVO its not working for once.

@Mitesh-Abacus
Copy link

What was the solution? , because we have already had no update in our app for the last 2-3 months, but
suddenly the app not getting location, please suggest how can resolve this.

@Nhc007
Copy link

Nhc007 commented Nov 23, 2022

@breautek We have been facing this same issue in OPPO, VIVO, REDMI, MI, OLD LG/MOTO Devices, Mostly having Android 12, If this issue is related with Android WebView even so, I tried downgrading and using the previous stable releases of it, but the issue still persists.
I'm confused that whether its android webview that is misbehaving or there is something else, as I've tried playing with different versions of it.

Edit: I've also posted on google android support community regarding webview.

@breautek
Copy link
Contributor

@breautek We have been facing this same issue in OPPO, VIVO, REDMI, MI, OLD LG/MOTO Devices, Mostly having Android 12, If this issue is related with Android WebView even so, I tried downgrading and using the previous stable releases of it, but the issue still persists. I'm confused that whether its android webview that is misbehaving or there is something else, as I've tried playing with different versions of it.

Edit: I've also posted on google android support community regarding webview.

I just wanted to add and make clear that this plugin doesn't actually implement any actual geolocation code for the android platform. What it does do is just handle the app permissions for geolocation.

So assuming this issue is not a permission issue and the app has all the relevant permissions, the next logical step to troubleshoot is the geolocation implementation itself, which is not implemented by Cordova.

@dragonfast
Copy link

I'm using this plugin instead:
cordova plugin add https://github.com/ToniKorin/cordova-plugin-location-provider.git
this plugin using LocationProvider natively, not W3C API and work on vivo, oppo, xiaomi.

cordova.plugins.LocationProvider.getOwnPosition(param like w3C, successcallback, errorcallback)

@Mr-Jeeva
Copy link

Found a workaround. Instead of using this plugin, can be fixed by writing custom plugin with native code (Location Manager or Fused Location).

@mobiliseapplabllp
Copy link

mobiliseapplabllp commented Nov 24, 2022 via email

@Mr-Jeeva
Copy link

Can anyone share the repository of the custom plugin with the native code? We would like to test the same in our application. We are struggling with this issue in our application working for several thousand users.

I'm still working on it (Testing it on various devices). Once it completed. Will share it

@utk4rsh92
Copy link

Can anyone share the repository of the custom plugin with the native code? We would like to test the same in our application. We are struggling with this issue in our application working for several thousand users. From: jeeva @.> Reply to: apache/cordova-plugin-geolocation @.> Date: Thursday, 24 November 2022 at 10:05 AM To: apache/cordova-plugin-geolocation @.> Cc: ASHISH SHARMA @.>, Comment @.> Subject: Re: [apache/cordova-plugin-geolocation] Unable to fetch Location on VIVO Devices (Issue #255) Found a workaround. Instead of using this plugin, can be fixed by writing custom plugin with native code (Location Manager or Fused Location). — Reply to this email directly, view it on GitHub<#255 (comment)>, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AKPRXN5PHUK4XNOO6D6ZSI3WJ3V4ZANCNFSM6AAAAAASGQFOLE. You are receiving this because you commented.Message ID: @.>

working with https://github.com/transistorsoft/cordova-background-geolocation-lt

@atmanegara
Copy link

I'm using this plugin instead: cordova plugin add https://github.com/ToniKorin/cordova-plugin-location-provider.git this plugin using LocationProvider natively, not W3C API and work on vivo, oppo, xiaomi.

cordova.plugins.LocationProvider.getOwnPosition(param like w3C, successcallback, errorcallback)

solved, works very well

@deepakpapney
Copy link

Can anyone share the repository of the custom plugin with the native code? We would like to test the same in our application. We are struggling with this issue in our application working for several thousand users. From: jeeva @.> Reply to: apache/cordova-plugin-geolocation _@**._> Date: Thursday, 24 November 2022 at 10:05 AM To: apache/cordova-plugin-geolocation _@.> Cc: ASHISH SHARMA @._>, Comment _@.> Subject: Re: [apache/cordova-plugin-geolocation] Unable to fetch Location on VIVO Devices (Issue #255) Found a workaround. Instead of using this plugin, can be fixed by writing custom plugin with native code (Location Manager or Fused Location). — Reply to this email directly, view it on GitHub<#255 (comment)>, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AKPRXN5PHUK4XNOO6D6ZSI3WJ3V4ZANCNFSM6AAAAAASGQFOLE. You are receiving this because you commented.Message ID: @.**_>

working with https://github.com/transistorsoft/cordova-background-geolocation-lt

please share code if it working

@deepakpapney
Copy link

orks very well

can you please share the code and changes you did
....

@prabusharan
Copy link

Can anyone share the repository of the custom plugin with the native code? We would like to test the same in our application. We are struggling with this issue in our application working for several thousand users. From: jeeva @.> Reply to: apache/cordova-plugin-geolocation _@**._> Date: Thursday, 24 November 2022 at 10:05 AM To: apache/cordova-plugin-geolocation _@.> Cc: ASHISH SHARMA @._>, Comment _@.> Subject: Re: [apache/cordova-plugin-geolocation] Unable to fetch Location on VIVO Devices (Issue #255) Found a workaround. Instead of using this plugin, can be fixed by writing custom plugin with native code (Location Manager or Fused Location). — Reply to this email directly, view it on GitHub<#255 (comment)>, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AKPRXN5PHUK4XNOO6D6ZSI3WJ3V4ZANCNFSM6AAAAAASGQFOLE. You are receiving this because you commented.Message ID: @.**_>

working with https://github.com/transistorsoft/cordova-background-geolocation-lt

please share code if it working

This is paid plugin

@atmanegara
Copy link

atmanegara commented Nov 24, 2022

orks very well

can you please share the code and changes you did ....

const options = {
    enableHighAccuracy: false,
    timeout: 30000,
    maximumAge: 0
  };
  
  function success(pos) {
    const crd = pos.coords;
  
    console.log('Your current position is:');
    console.log(`Latitude : ${crd.latitude}`);
    console.log(`Longitude: ${crd.longitude}`);
    console.log(`More or less ${crd.accuracy} meters.`);
  }
  
  function error(err) {
    console.warn(err);
    console.warn(`ERROR(${err.code}): ${err.message}`);
  }
  
 // navigator.geolocation.getCurrentPosition(success, error, options);
 cordova.plugins.LocationProvider.getOwnPosition(options,success,error)```

@deepakpapney
Copy link

getOwnPosition

giving error at plugins.Locationprovider???

@atmanegara
Copy link

getOwnPosition

giving error at plugins.Locationprovider???

whether to use this plugin https://github.com/ToniKorin/cordova-plugin-location-provider.git

@jubinpatel

This comment was marked as off-topic.

@sonikdesign
Copy link

sonikdesign commented Nov 25, 2022

Hi all,
I've the same issue with cordova-plugin-geolocation in some devices with Android 12. I've tried:
"cordova-plugin-locationservices": "^2.1.0"
it works (on an Android device without troubles with recent Webview updates, I've not tested APK in devices with troubles), but it's too slow on first execution. The app freezes visually, then resumes working properly.

I'm working with cordova in a Quasar V1 project. This is the code used with this locationservices plugin:

cordova.plugins.locationServices.geolocation.getCurrentPosition(onSuccess, onError, options)

I'm sorry not to confirm if the solution works or not, but with this app freeze issue I can't ask customers to test it.

@gohrms
Copy link

gohrms commented Nov 26, 2022

I am using IONIC application and using geolocation '@awesome-cordova-plugins/geolocation/ngx'. This was working fine but since last few days it stopped. I am trying now to use "cordova-plugin-locationservices" with cordova.plugins.locationServices.geolocation.getCurrentPosition(onSuccess, onError, options) but it is giving me "property locationServices does on exists on type CordovaPlugins". Kindly help.

@gohrms
Copy link

gohrms commented Nov 27, 2022

  1. cordova-plugin-locationservices-fix

this solved too

Are you using ionic. Can you please share your sample code and specially which Import module did you use for "cordova.plugins.locationServices"

@waptaxi
Copy link

waptaxi commented Nov 28, 2022

If anybody can confirm that using the latest system webview solves the problem, then I think it helps prove that the issue indeed was in the android webview.

Tried the latest webview 107, beta webview 108, dev webview 109 - none of them solves the problem

@amnuaycn
Copy link

amnuaycn commented Nov 28, 2022

I am using IONIC and change "cordova-plugin-geolocation" to @capacitor/geolocation it working

//import { Geolocation } from '@ionic-native/geolocation/ngx';
//import { LocationAccuracy } from '@ionic-native/location-accuracy/ngx';
import { Geolocation,PositionOptions } from '@capacitor/geolocation';
...
public options: PositionOptions = {
    timeout: 5000, 
    enableHighAccuracy: true, 
    maximumAge: 3000
  };
...

/*async getCurrentCoordinates() {
    this.geolocation.getCurrentPosition(this.options).then((resp) => {
      this.latitude = resp.coords.latitude;
      this.longitude = resp.coords.longitude;
      console.log('accuracy:',resp.coords.accuracy);
     }).catch((error) => {
       console.log('Error getting location', error);
     });
  }
*/
  async getCurrentCoordinates() {
    const position = await Geolocation.getCurrentPosition(this.options);
    console.log('accuracy:',position.coords.accuracy);
    this.latitude = position.coords.latitude;
    this.longitude = position.coords.longitude;
  }

@gohrms
Copy link

gohrms commented Nov 28, 2022

I am using IONIC and change "cordova-plugin-geolocation" to @capacitor/geolocation it working

//import { Geolocation } from '@ionic-native/geolocation/ngx';
//import { LocationAccuracy } from '@ionic-native/location-accuracy/ngx';
import { Geolocation,PositionOptions } from '@capacitor/geolocation';
...
public options: PositionOptions = {
    timeout: 5000, 
    enableHighAccuracy: true, 
    maximumAge: 3000
  };
...

/*async getCurrentCoordinates() {
    this.geolocation.getCurrentPosition(this.options).then((resp) => {
      this.latitude = resp.coords.latitude;
      this.longitude = resp.coords.longitude;
      console.log('accuracy:',resp.coords.accuracy);
     }).catch((error) => {
       console.log('Error getting location', error);
     });
  }
*/
  async getCurrentCoordinates() {
    const position = await Geolocation.getCurrentPosition(this.options);
    console.log('accuracy:',position.coords.accuracy);
    this.latitude = position.coords.latitude;
    this.longitude = position.coords.longitude;
  }

You mean to say, to convert the ionic cordova project to ionic capacitor project ? I tried to add capacitor in my cordova project and it gives me error "SyntaxError: Unexpected token '('" in adb logcat.

@dsmalicsi
Copy link

I'm using this plugin instead: cordova plugin add https://github.com/ToniKorin/cordova-plugin-location-provider.git this plugin using LocationProvider natively, not W3C API and work on vivo, oppo, xiaomi.

cordova.plugins.LocationProvider.getOwnPosition(param like w3C, successcallback, errorcallback)

This solution doesn't work for devices that doesn't have Google Play Services like Huawei. I hope anyone could share any alternative that they could find. Thanks!

Screenshot 2022-11-29 at 10 25 54 AM

@sonikdesign
Copy link

Has anyone figured out what changes need to be made to the native code to avoid isues with geolocation? These 6-7 year old plugins, in a cordova application, just gave me compile problems, so I wasn't even able to test them.
Thanks to all who are looking for a solution.

@Soundariya-Bingu
Copy link

Soundariya-Bingu commented Nov 29, 2022

I am using IONIC and change "cordova-plugin-geolocation" to @capacitor/geolocation it working

//import { Geolocation } from '@ionic-native/geolocation/ngx';
//import { LocationAccuracy } from '@ionic-native/location-accuracy/ngx';
import { Geolocation,PositionOptions } from '@capacitor/geolocation';
...
public options: PositionOptions = {
    timeout: 5000, 
    enableHighAccuracy: true, 
    maximumAge: 3000
  };
...

/*async getCurrentCoordinates() {
    this.geolocation.getCurrentPosition(this.options).then((resp) => {
      this.latitude = resp.coords.latitude;
      this.longitude = resp.coords.longitude;
      console.log('accuracy:',resp.coords.accuracy);
     }).catch((error) => {
       console.log('Error getting location', error);
     });
  }
*/
  async getCurrentCoordinates() {
    const position = await Geolocation.getCurrentPosition(this.options);
    console.log('accuracy:',position.coords.accuracy);
    this.latitude = position.coords.latitude;
    this.longitude = position.coords.longitude;
  }

I used these links to install:
https://www.npmjs.com/package/@capacitor/geolocation#getcurrentposition
https://capacitorjs.com/docs/apis/geolocation

But getting this error in the console tab on the browser, I am using IONIC 5 in my Mobile app
Here is the error screenshot:

Screenshot_2022-11-29_16-12-24

Please help somebody, I struck for 2 days I tried so many things but nothing is working as expected.

Advance thanks to all who are looking for a solution.

@mobiliseapplabllp
Copy link

google announce (Security and privacy) section
https://developer.android.com/about/versions/12/behavior-changes-all

for security reason google can't access [ACCESS_FINE_LOCATION] on some Android 12 Mobile. it access only ACCESS_COARSE_LOCATION.
but i remove ACCESS_FINE_LOCATION from my project. i access only ACCESS_COARSE_LOCATION but problem not solve

@sonikdesign
Copy link

sonikdesign commented Nov 29, 2022

https://developer.android.com/about/versions/12/behavior-changes-all

We have problems after Android updates on devices with Android 8.1.0, 11 and 12.

With cordova-plugin-geolocation I have a timeout error (after 60 secs) in these devices.

@newtonstudio
Copy link

Hi Guys, I'm also suffering from this issue since few weeks ago.
After doing some research, i try to combine several methods by solving this issue. In summary:

  1. Go to google play and update user mobile to latest android web view version.
  2. Install LocationProvider cordova plugin (use ts-ignore to prevent ionic build error)
  3. enable timeout option on geolocation, and try use LocationProvider if geolocation has failed.

It works for me. Hope it helps.

My Environment is Angular+Ionic 4 with Cordova.

I tried to install two of this plugin:
cordova-plugin-geolocation 4.1.0 "Geolocation"
cordova-plugin-location-provider 1.5.4 "LocationProvider"

in my ts file:

import { Geolocation, GeolocationOptions } from '@ionic-native/geolocation';
import { Platform } from '@ionic/angular';
//dependency injection
constructor(private geolocation: Geolocation, private platform: Platform){}

somefunction(){
  this.geolocation.getCurrentPosition({ maximumAge: 3000, timeout: 5000, enableHighAccuracy: false }).then((resp) => {
    //do something
  }).catch((error) => {
        
        //can use platform to do platfom specific code here
	//@ts-ignore
	cordova.plugins.LocationProvider.getOwnPosition({ maximumAge: 3000, timeout: 5000, enableHighAccuracy: false },(resp)=>{
         //do something
        }, (error)=>{
        //do something
        });
}

@mobiliseapplabllp
Copy link

mobiliseapplabllp commented Nov 30, 2022 via email

@gohrms
Copy link

gohrms commented Nov 30, 2022

Seems like Android is playing games with IONIC and CORDOVA and making us inclined towards native technologies like Flutter. But mind you Android this is not the right way. Yes, any simple successful solution is highly appreciated, the users of the app are suffering because of these mess.

@sonikdesign
Copy link

Can anyone tell me where to report this issue with the latest Android updates? Because these updates are creating quite a few problems, several important frameworks are involved and so many days have gone by without finding a solution.

@sonikdesign
Copy link

Can anyone tell me where to report this issue with the latest Android updates? Because these updates are creating quite a few problems, several important frameworks are involved and so many days have gone by without finding a solution.

I answer to myself: https://issuetracker.google.com/

@breautek
Copy link
Contributor

I'm closing this issue because it doesn't appear to be related to Cordova.

To recap, Cordova doesn't implement any actual geolocation features for the Android platform. What the Cordova plugin does do is handle geolocation permissions for the application, hooking into the Webview's geolocation implementation. So in otherwords, the geolocation feature is provided by the system webview itself. Because this issue does not appear to be a permissions related issue, there isn't anything Cordova can do to resolve this problem.

Out of all the comments, the devices that is affected (Vivo, Oppo, Xioami, etc...). These devices often don't use standard AOSP software. I don't have access to any of these devices for testing, but the standard AOSP system webview appears to work as expected. And I know that some of these devices do not use, or uses a fork of the standard AOSP webview. Vivo for example has their own VivoBrowser that appears to be used based on the user agent. Unfortunately I do not have an answer of why this is happening on these specific devices, I just know that it's not something Cordova can correct. It's very likely an issue within their system webview implementation.

As for potential workarounds, several developers have posted success utilizing an alternate geolocation plugin that uses the native APIs instead of the browser-based APIs that this Cordova plugin relies on. So that may be a path to consider. Cordova will not implement a native-based implementation as a workaround as there are many community plugins that does this already.

@breautek breautek closed this as not planned Won't fix, can't repro, duplicate, stale Nov 30, 2022
@gohrms
Copy link

gohrms commented Dec 1, 2022

It will be helpful if the issue is kept open to get more ideas and solution from people.

@gohrms
Copy link

gohrms commented Dec 1, 2022

I had the same issue on my Vivo x70, today there was some auto update on play services and then I did restart the phone and now the same App has started working with GPS location being captured properly. I am not sure exactly was auto updated today on my phone. Can anyone try to update the "Play Services" and then retry.

As need to give solutions to the users who are facing the same issue.

It will be helpful if the issue is kept open to get more ideas and solution from people.

@sonikdesign
Copy link

sonikdesign commented Dec 5, 2022

Issue will be resolve, follow these instructions.

  1. Use this plugin which is free available on GitHub or npm.
    cordova-plugin-locationservices-fix
  2. In code use LocationServices instead of navigator.geolocation
    i.e. LocationServices.getCurrentPosition(,,)

how do you import it into your project? I found LocationServices.getCurrentPosition in:
cordova.plugins.locationServices.geolocation.getCurrentPosition(onSuccess, onError, options)
but my app freeze the first time this method is called.

@ravi106
Copy link

ravi106 commented Dec 5, 2022

After Adding this plugin - cordova-plugin-locationservices-fix.Try this.
let trackGps;
public captureCurrentLocation() {
if (trackGps) {
(window as any).LocationServices.clearWatch(this.trackGps);
}
const options = { // options for capturing the geolocation
enableHighAccuracy: true,
timeout: 10000,
maximumAge: 0,
};
const success = (position: any) => {
console.log('Your current position is:');
console.log(Latitude & Longitude : ${position});
}
const error = (err: any) => {
console.log(ERROR(${err.code}): ${err.message});
}
trackGps = (window as any).LocationServices.watchPosition(success, error, options);
}

@009topersky
Copy link

009topersky commented Dec 6, 2022

Good day everyone!
our team are using ionic 4 in our application,
To solve the issue we use the https://github.com/mapsplugin/cordova-plugin-googlemaps.

First, you have to follow the instruction on the documentation and get the API KEY from Google.
setup your project here: https://console.cloud.google.com/apis/credentials?authuser=2

Second, in config.xml add this line or you can read it on the documentation of the plugin:

<preference name="GOOGLE_MAPS_ANDROID_API_KEY" value="YOUR_API_KEY_FROM_GOOGLE_CONSOLE" />

Third, under app.module.ts include the LocationService

@NgModule({
  declarations: [AppComponent],
  entryComponents: [],
  imports: [
           ....
           LocationService
           ....
           ]
});

Fourth, import the LocationService and create a function to get the geolocaion.

import {
  LocationService,
  MyLocation,
  MyLocationOptions
} from '@ionic-native/google-maps';

....

async getGoogleCurrentLocationAsync() {
    const options: MyLocationOptions = { enableHighAccuracy: true };
    
    return await LocationService.getMyLocation().then((myLocation) => {
      if (myLocation) {
        const coordinate: Coordinates = {
          latitude: myLocation.latLng.lat,
          longitude: myLocation.latLng.lng,
          accuracy: myLocation.accuracy,
          altitude: myLocation.altitude,
          speed: myLocation.speed,
          altitudeAccuracy: null,
          heading: null,
        }; 
  
        return coordinate;
      }
      return false;
    },
    (_error) => false)
    .catch((_e) => false)
  }

That's it!
I hope this answer will help!

Thanks

@mobiliseapplabllp
Copy link

Good day everyone! our team are using ionic 4 in our application, To solve the issue we use the https://github.com/mapsplugin/cordova-plugin-googlemaps.

First, you have to follow the instruction on the documentation and get the API KEY from Google. setup your project here: https://console.cloud.google.com/apis/credentials?authuser=2

Second, in config.xml add this line or you can read it on the documentation of the plugin:

<preference name="GOOGLE_MAPS_ANDROID_API_KEY" value="YOUR_API_KEY_FROM_GOOGLE_CONSOLE" />

Third, under app.module.ts include the LocationService

@NgModule({
  declarations: [AppComponent],
  entryComponents: [],
  imports: [
           ....
           LocationService
           ....
           ]
});

Fourth, import the LocationService and create a function to get the geolocaion.

import {
  LocationService,
  MyLocation,
  MyLocationOptions
} from '@ionic-native/google-maps';

....

async getGoogleCurrentLocationAsync() {
    const options: MyLocationOptions = { enableHighAccuracy: true };
    
    return await LocationService.getMyLocation().then((myLocation) => {
      if (myLocation) {
        const coordinate: Coordinates = {
          latitude: myLocation.latLng.lat,
          longitude: myLocation.latLng.lng,
          accuracy: myLocation.accuracy,
          altitude: myLocation.altitude,
          speed: myLocation.speed,
          altitudeAccuracy: null,
          heading: null,
        }; 
  
        return coordinate;
      }
      return false;
    },
    (_error) => false)
    .catch((_e) => false)
  }

That's it! I hope this answer will help!

Thanks

Thanks for your answer

How many mobiles have you tested this code on?

@sonikdesign
Copy link

There's an Android WebView update, but the issue persists with Oppo's and Vivo's devices

@009topersky
Copy link

009topersky commented Dec 6, 2022

Good day everyone! our team are using ionic 4 in our application, To solve the issue we use the https://github.com/mapsplugin/cordova-plugin-googlemaps.
First, you have to follow the instruction on the documentation and get the API KEY from Google. setup your project here: https://console.cloud.google.com/apis/credentials?authuser=2
Second, in config.xml add this line or you can read it on the documentation of the plugin:
<preference name="GOOGLE_MAPS_ANDROID_API_KEY" value="YOUR_API_KEY_FROM_GOOGLE_CONSOLE" />
Third, under app.module.ts include the LocationService

@NgModule({
  declarations: [AppComponent],
  entryComponents: [],
  imports: [
           ....
           LocationService
           ....
           ]
});

Fourth, import the LocationService and create a function to get the geolocaion.

import {
  LocationService,
  MyLocation,
  MyLocationOptions
} from '@ionic-native/google-maps';

....

async getGoogleCurrentLocationAsync() {
    const options: MyLocationOptions = { enableHighAccuracy: true };
    
    return await LocationService.getMyLocation().then((myLocation) => {
      if (myLocation) {
        const coordinate: Coordinates = {
          latitude: myLocation.latLng.lat,
          longitude: myLocation.latLng.lng,
          accuracy: myLocation.accuracy,
          altitude: myLocation.altitude,
          speed: myLocation.speed,
          altitudeAccuracy: null,
          heading: null,
        }; 
  
        return coordinate;
      }
      return false;
    },
    (_error) => false)
    .catch((_e) => false)
  }

That's it! I hope this answer will help!
Thanks

Thanks for your answer

How many mobiles have you tested this code on?

We are testing this solution in Vivo, Samsung, Xiaomi, Huawei and OnePlus devices and from different Android API versions (9,10,11 and 12)

@sonikdesign
Copy link

sonikdesign commented Dec 7, 2022

The December 2 update Android System WebView works on both Android 8.1 and 12. If the update doesn't work, you'll need to remove and install Android System WebView.

@mobiliseapplabllp
Copy link

https://github.com/mapsplugin/cordova-plugin-googlemaps.

hello
how to install "https://github.com/mapsplugin/cordova-plugin-googlemaps". this plugin. when we create apk its showing error please provide npm command

Thanks

@009topersky
Copy link

https://github.com/mapsplugin/cordova-plugin-googlemaps.

hello how to install "https://github.com/mapsplugin/cordova-plugin-googlemaps". this plugin. when we create apk its showing error please provide npm command

Thanks

You can check the documentation here:
https://github.com/ionic-team/ionic-native-google-maps/blob/master/documents/README.md

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests