Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Location from coordinates

I have given coordinates for latitude and longitude, and I want make a location object with those.There isn't a constructor that takes to doubles to make a location, so I tried like this:

 Location l = null;
 l.setLatitude(lat);
 l.setLongitude(lon);

but it crashes. Any different idea?

like image 542
NiVeR Avatar asked May 20 '12 20:05

NiVeR


People also ask

Can you find an address from coordinates?

Finding an address using longitude and latitude is easy if you have access to a computer or phone. You can use a reverse geocoding tool or Google Maps to pull up the address listed at your given coordinates.

How do I enter coordinates into Iphone maps?

Get the coordinates of a placeTouch and hold an area of the map that isn't labeled to drop a red pin. At the bottom, tap Dropped pin to find the coordinates.

Can you enter GPS coordinates on Iphone?

If you don't have an address for a place, you can enter the GPS coordinates directly into the Maps location and the location will be displayed. Open the Maps app. Tap Search at the bottom of the screen. Enter the latitude and longitude coordinates in the search bar.


2 Answers

Just create a new Location with new Location("reverseGeocoded"); like this

GeoPoint newCurrent = new GeoPoint(59529200, 18071400);
        Location current = new Location("reverseGeocoded");
        current.setLatitude(newCurrent.getLatitudeE6() / 1e6);
        current.setLongitude(newCurrent.getLongitudeE6() / 1e6);
        current.setAccuracy(3333);
        current.setBearing(333);
like image 99
Jonathan Avatar answered Sep 19 '22 12:09

Jonathan


This crashes because you cannot call methods on an non existent object.

I presume you are talking about android.location.Location?

This is usually returned by the various positioning services of Android. What do you want to do with it?

Do you want to reverse geocode it? As in find an address for that geo coordinate?

Or do you want to use it as a "fake" position and feed it to other applications?

There are BTW two constructors. One takes the name of a positioning service and the other is a copy constructor and takes an existing Location.

So you could create a Location like this:

Location l = new Location("network");

But I do not think that this will result in something you want to have.

Here is a link to the documentation:

https://developer.android.com/reference/android/location/Location.html#Location%28java.lang.String%29

like image 34
Dirk Jäckel Avatar answered Sep 19 '22 12:09

Dirk Jäckel