-2
사용자의 현재 주소 (역 지오테이션)를 보여주는 안드로이드 앱을 작성하려고하는데 현재 위치에 마커를 놓았지만 현재 주소는 제공하지 않습니다. 내가 무엇을 놓치고 정말로 그것을 누군가가 바른 방향으로 나를 가르 킬 수 있는지에 관해 알 것 인 것을 나는 확신하지 않는다.Google지도 Android 현재 주소 얻기
공용 클래스 위치는 Geocoder
이 올바른 접근 방식 사용 활동 {
public GoogleMap map;
public Marker myLocation;
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
if(myLocation!=null)
myLocation.remove();
myLocation=map.addMarker(new MarkerOptions().position(latlng).icon(BitmapDescriptorFactory.defaultMarker(
BitmapDescriptorFactory.HUE_MAGENTA)).title("Your Current Location."));
double lat = location.getLatitude();
double lng = location.getLongitude();
latLongString = "Lat:" + lat + "\nLong:" + lng;
double latitude = location.getLatitude();
double longitude = location.getLongitude();
Geocoder coder = new Geocoder(this, Locale.getDefault());
if (!Geocoder.isPresent())
addressString = "No geocoder available";
else {
try {
List<Address> addresses = coder.getFromLocation(latitude, longitude, 1);
StringBuilder sb = new StringBuilder();
if (addresses.size() > 0) {
Address address = addresses.get(0);
for (int i = 0; i < address.getMaxAddressLineIndex(); i++)
sb.append(address.getAddressLine(i)).append("\n");
sb.append(address.getLocality()).append("\n");
sb.append(address.getPostalCode()).append("\n");
sb.append(address.getCountryName());
}
addressString = sb.toString();
} catch (IOException e) {
}
}
}
myLocationText.setText("Your Current Position is:\n" +
latLongString + "\n\n" + addressString);
}
private final LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
updateWithNewLocation(location);
}
public void onProviderDisabled(String provider) {}
public void onProviderEnabled(String provider) {}
public void onStatusChanged(String provider, int status,
Bundle extras) {}
};
}
@sulia 예외가 없으며 코드가 잘 실행되어 현재 주소가 인쇄되지 않습니다. – user3493849
당신의 IDE 디버거를 사용하여 버그를 찾으려고 했습니까? 귀하의 경우에'coder.getFromLocation (...)'의 결과는 무엇입니까? – sulai
코드를 실행하면 현재 위치 문을 인쇄하고 마커를 배치하지만 long/lat 또는 주소는 인쇄하지 않습니다. – user3493849