androidcurious androidcurious - 1 month ago 19
Android Question

Convert Location to GeoPoint

All- I am trying to get the user's current location than display that on the map with an overlay item. My problem is the user's location is coming in as a location and the overlay array only accepts GeoPoints. Here is what I have tried:

LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
GeoPoint point = new GeoPoint.valueOf(location);
OverlayItem overlayitem4 = new OverlayItem(point, "You Are Here", "Boulder, CO");
}


But I am getting an error on
GeoPoint.valueOf(location);
, specifically:


GeoPoint.valueOf cannot be resolved to a type`


So my question is How can I convert from location to GeoPoint? Thank you all for your time.

Answer

try this

LocationListener locationListener = new LocationListener() {

     public void onLocationChanged(Location location) {      
         int lat = (int) (location.getLatitude() * 1E6);
         int lng = (int) (location.getLongitude() * 1E6);
         GeoPoint point = new GeoPoint(lat, lng);
         OverlayItem overlayitem4 = new OverlayItem(point, "You Are Here",   "Boulder, CO"); 
     }
}