0

Guyz I need to get user current location as an latitude and longitude,so I had defined GeoPoint getLocationFromAddress(String strAddress) which takes steAddress as parameter which string addres and then return p1 as geopoint variable.Now my question is that how should I extract latitude and longitude seperately from it so that I can use in request url of google places api.I printed the value of that p1 variable in logcat its 192508911, 731430546. below is my calling function:

   GeoPoint lnglat=getLocationFromAddress(keyword);
   System.out.println(lnglat);
   Log.d("Location Point",lnglat.toString() ); 

and here below is the returning function:

    public GeoPoint getLocationFromAddress(String strAddress){

    Geocoder coder = new Geocoder(this);
    List<Address> address;
    GeoPoint p1 = null;

    try {
    address = coder.getFromLocationName(strAddress,5);
    if (address == null) {
        return null;
    }
    Address location = address.get(0);
    location.getLatitude();
    location.getLongitude();

    p1 = new GeoPoint((int) (location.getLatitude() * 1E6),
                      (int) (location.getLongitude() * 1E6));

    return p1;
    }
    catch(Exception e){
    e.printStackTrace();
    }
    return p1;
   }
user3930098
  • 395
  • 7
  • 14

1 Answers1

0

GeoPoint class has specific methods:

double lat = lnglat.getLatitude();

double lon = lnglat.getLongitude();

https://developer.mapquest.com/content/mobile/android/documentation/api/com/mapquest/android/maps/GeoPoint.html#getLatitude()

GioLaq
  • 2,489
  • 21
  • 26
  • but now the problem is that it is placing dot'.' after 1st digit like 1.92508911, 7.31430546 whereas it proper format is 19.2508911, 73.1430546.How can I get in Proper format? – user3930098 Oct 22 '14 at 15:46
  • And also it not accepting double lat = lnglat.getLatitude(); double lon = lnglat.getLongitude(); I need to write it as double lat = lnglat.getLatitudeE6(); when I write code as double lat = lnglat.getLatitude(); it says The method getLatitude() is undefined for the type GeoPoint. So I required to change to double lat = lnglat.getLatitudeE6(); double lng = lnglat.getLongitudeE6(); – user3930098 Oct 22 '14 at 15:47