Android - address to ParseGeoPoint

摘要:Android - address to ParseGeoPoint


    public static ParseGeoPoint getParseGeoByAddress(Context ctx,String address){
        ParseGeoPoint geo = null ;
        Geocoder geocoder = new Geocoder(ctx,Locale.getDefault());
        try {
            List list = geocoder.getFromLocationName(address, 70 ) ;
            if(!list.isEmpty()){
                Address location = list.get(0);
                
                double lat = location.getLatitude()  ;
                double lon = location.getLongitude()  ;
                geo  = new ParseGeoPoint(lat,lon) ;
            }
        } catch (IOException e) {       
            
            e.printStackTrace();
        } 
        return geo  ; 
    }