简体   繁体   中英

How to get latitude and longitude by address location in Android

I am developing Android app in which I am taking destination in edit-text and I want latitude and longitude of that entered location.

example: I have typed in edit-text pune now I want its latitude and longitude.

From here : https://stackoverflow.com/a/3574792/2065418

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

    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;
    }

strAddress is a string containing the address. The address variable holds the converted addresses.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM