将地址转换为geopoint

use*_*684 2 android google-maps

我希望用户使用google places api输入他想要搜索附近位置的位置.我想知道如何将字符串转换为geopoints?

Mis*_*waj 7

你可以通过简单地调用getFromLocationName()来做到这一点

Geocoder geoCoder = new Geocoder(context, Locale.getDefault());     
 try {
        List<Address> address = geoCoder.getFromLocationName(locationName, 1);    
        double latitude = address.get(0).getLatitude();
        double longitude = address.get(0).getLongitude();            
    } catch (IOException e) {
        e.printStackTrace();
    }
Run Code Online (Sandbox Code Playgroud)