簡體   English   中英

地理編碼從地址獲取緯度和經度

[英]Geocode get Latitude and Longitude from address

我試圖從ArrayList中的地址獲取經度和緯度,並在另一個Arraylist中寫入緯度和經度。 沒用 在ArrayList中,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++;
        }

在這里,我為您提供了從地址獲取經/緯度的示例代碼。 嘗試這個 :

 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();

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM