38

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?

2 Answers 2

73

Use static methodLocationRequest create ().

 LocationRequest locationRequest = LocationRequest.create();
 locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
 locationRequest.setInterval(5000);
 locationRequest.setFastestInterval(1000);
3
  • 1
    It is mentioned in doc i guess but not clearly . if you see the Source code then you will see the constructor is hide . And also constructor is no where mentioned in docs so create() is the ultimate solution.
    – ADM
    Mar 26, 2018 at 10:31
  • 1
    @ADM Where is it mentioned? The doc says: "Create the location request and set the parameters as shown in this code sample: protected void createLocationRequest() { LocationRequest mLocationRequest = new LocationRequest(); mLocationRequest.setInterval(10000); mLocationRequest.setFastestInterval(5000); mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); } If you do this you get the annoying warning. The documentation is real crap most of the time. Mar 29, 2018 at 6:11
  • 2
    Yeah you are right about the Doc. But what in look up is LocationRequest class . And there is no public constructor listed . And also if you go through the source code you will see than constructor is hide . I can not say much about the Doc but to me it seems a bit misleading.
    – ADM
    Mar 29, 2018 at 6:22
15

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();

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.