Question

I have a lot of geo data stored online with latitude and longitude and I'd like to use the distanceTo method instead of my own haversine formula.

So I need to put each record into a Location field, but here's my question: it requires a "provider" string. Why? What will Android do with that information?

    for (ArrayList<String> item : Places_Data) {
        Location itemloc = new Location("provider");
        itemloc.setLatitude(latIn);
        itemloc.setLongitude(lonIn);
        //do something with my new location
    }
Was it helpful?

Solution

From the source code for Location, it doesn't use the string to do anything meaningful. It just uses it to describe the Location internally. If you do Location#toString(), it prints out the co-ordinates, the provider and other details (accuracy, etc). That's all it's used for, internal description.

You can make the provider anything, as seen in this answer: Creating Android Location Object

OTHER TIPS

Use correctly the way

package android.location.LocationManager
Location location = new Location(LocationManager.GPS_PROVIDER);

Use NETWORK_PROVIDER o GPS_PROVIDER

https://developer.android.com/reference/android/location/LocationManager.html#GPS_PROVIDER

https://developer.android.com/reference/android/location/LocationManager.html#NETWORK_PROVIDER

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top