Finding Location : Google Play Location Service or Android platform location APIs

后端 未结 2 551
礼貌的吻别
礼貌的吻别 2020-12-25 09:36

i am trying to get the users location for my new navigation app. i want to check the users location frequently and it has to be accurate . I use the following code from samp

相关标签:
2条回答
  • 2020-12-25 09:59

    Absolutely use the new google play location services. They work much better indoors than the old location manager. I have created a sample that uses the new google play location services and works in the background periodically. Check it out:

    https://github.com/nickfox/GpsTracker/tree/master/phoneClients/android

    0 讨论(0)
  • 2020-12-25 10:11

    When I was working with it, I came across 2 good sources:

    1. The blog post: Android Location Fused Provider. It includes a great complete tutorial on using the FusedLocationProviderApi to get location in Android.

    2. Answers on following Android LocationClient class is deprecated but used in documentation question.

    Basically both talk about the similar steps as mentioned in the Google I/O session, link to which is mentioned in one of the answers:

    • First, to get a GoogleClientApi instance, like:

      GoogleClientApi googleApiClient = new GoogleApiClient.Builder(locationActivity)
              .addApi(LocationServices.API)
              .addConnectionCallbacks(this)
              .addOnConnectionFailedListener(this)
              .build();
      
    • Then to call .connect() on it like:

      googleApiClient.connect();
      
    • Then in the callback onConnected, get the last location or even can request the location updates as per your need, eg:

      LocationServices.FusedLocationApi.getLastLocation(googleApiClient);
      

      If you want request location updates, then can use the requestLocationUpdates call.

    Hope it helps.

    0 讨论(0)
提交回复
热议问题