Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 662
ninge Avatar asked Dec 15 '22 21:12

ninge


2 Answers

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"); 
     }
}
like image 193
Xenione Avatar answered Jan 08 '23 22:01

Xenione


This worked for me and it seems much easier:

GeoPoint geoPoint = new GeoPoint(location);
like image 27
Ilya Kogan Avatar answered Jan 08 '23 22:01

Ilya Kogan