使用url方式去請求,回傳下面的結果。 api的key設定是沒有問題的。
https://maps.googleapis.com/maps/api/place/autocomplete/json?latlng="+lat+","+lng+"&radius=10000&input=madrid&components=country:ph&types=(regions)&key=我的key
"error_message" : "This API project is not authorized to use this API.",
"results" : [],
"status" : "REQUEST_DENIED"
改成geocoder的方式:
List<Address> addresses = geocoder.getFromLocation(
location.getLatitude(), location.getLongitude(), 1
);
for (Address address : addresses) {
Log.i("TAG", "address = " + address.toString());
}
if (addresses != null) {
addr = addresses.get(0).getAddressLine(0);
mAddress = addresses.get(0);
lat = location.getLatitude() + "";
lng = location.getLongitude() + "";
Log.i(TAG, "run: addr = " + addr + "," + mAddress.getLatitude() + "," + mAddress.getLongitude());
}
得到的結果只決議到城市名Philippines(PH)_Manila_Manila,沒有具體的路段或者建筑名稱,在國內的地址是正常的包含區縣路段建筑等,到了國外就不正常了。
有沒有大神知道怎么解決?
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/119701.html
標籤:Android
