Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LocationRequest constructor is marked as internal

I'm trying to set up location updates in my Android app using com.google.android.gms:play-services-location:12.0.0, but I'm getting the following error:

LocationRequest constructor is marked as internal and should not be accessed from apps

My location updates request looks like this:

locationClient.requestLocationUpdates(
    new LocationRequest()
        .setInterval(5000)
        .setFastestInterval(1000)
        .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY),
    locationCallback,
    null
);

I have followed the docs and the example, which do it the same way. If I'm not supposed to call new LocationRequest(), then what is the proper way to do it?

like image 939
Duncan Luk Avatar asked Mar 26 '18 10:03

Duncan Luk


People also ask

What is the use of the locationrequest object?

LocationRequest objects are used to request a quality of service for location updates from the FusedLocationProviderApi. For example, if your application wants high accuracy location it should create a location request with setPriority (int) set to PRIORITY_HIGH_ACCURACY and setInterval (long) to 5 seconds.

How to initialize locationrequest in Android?

Use static method LocationRequest create (). Show activity on this post. LocationRequest initialization procedure has changed into latest Google Play Service dependencies ( > 12.0.0). Now you can use its create () method to initialize this. e.g. Show activity on this post.

Are location requests considered hints?

All location requests are considered hints, and you may receive locations that are more/less accurate, and faster/slower than requested. Used with setPriority (int) to request "block" level accuracy.

How to create a location request with high accuracy?

For example, if your application wants high accuracy location it should create a location request with setPriority(int) set to PRIORITY_HIGH_ACCURACY and setInterval(long) to 5 seconds. This would be appropriate for mapping applications that are showing your location in real-time.


2 Answers

Use static methodLocationRequest create ().

 LocationRequest locationRequest = LocationRequest.create();  locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);  locationRequest.setInterval(5000);  locationRequest.setFastestInterval(1000); 
like image 110
ADM Avatar answered Sep 24 '22 06:09

ADM


LocationRequest initialization procedure has changed into latest Google Play Service dependencies ( > 12.0.0). Now you can use its create() method to initialize this. e.g.

LocationRequest request = LocationRequest.create(); 
like image 24
Rahul Sharma Avatar answered Sep 21 '22 06:09

Rahul Sharma