1
我正在使用谷歌地圖V2。我想使用geocoder
找到位置,但是getFromLocationName()
它返回空值,我無法找到原因。只要看看我的代碼並建議我,我該怎麼辦?爲什麼Geocoder.getFromLocationName返回null?
EditText sLocation = (EditText) v.findViewById(R.id.editText1);
String location = sLocation.getText().toString();
List<android.location.Address> addressList= null;
if (location != null || !location.equals("")) {
Geocoder geocoder = new Geocoder(getActivity().getApplicationContext());
try {
addressList = geocoder.getFromLocationName(location, 1);
} catch (IOException e) {
e.printStackTrace();
}
android.location.Address address = addressList.get(0);
LatLng latlng = new LatLng(address.getLatitude(), address.getLatitude());
gMap.addMarker(new MarkerOptions().position(latlng).title("Marker"));
gMap.animateCamera(CameraUpdateFactory.newLatLng(latlng));
}
入住這太問題[4567216](http://stackoverflow.com/questions/4567216/geocoder-getfromlocationname-returns-only -null)和[15182853](http://stackoverflow.com/questions/15182853/android-geocoder-getfromlocationname-always-returns-null)如果它可以幫助你。 – KENdi
@KENdi,我解決了我的問題。請看我下面的答案。 –