地理编码从地址获取纬度和经度

时间:2014-07-29 17:05:57

标签: java android arraylist geocoding

我试图从ArrayList中的地址获取纬度和经度,并在另一个Arraylist中写入纬度和经度。它不起作用。 在ArrayList中,User是User的地址, 在ArrayList中,latlon是纬度和经度。

Geocoder coder = new Geocoder(this);
        Iterator<User>ite=Profile.User.listIterator();
        List<Address>address;
        User temp=null;
        int br=0;
        while(ite.hasNext()){
            temp=ite.next();
            address=coder.getFromLocationName(temp.Useraddress,1);
            Address location = address.get(br);
            UserLocation.latlon.add(new latlon(location.getLatitude(), location.getLongitude()));
            br++;
        }

1 个答案:

答案 0 :(得分:0)

我在这里为您提供了从地址获取纬度/经度的示例代码。试试这个:

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

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

}
相关问题