나는 사용자가 입력 한 다음 사용자가 입력 한지도를 중앙에 배치하는 앱을 개발 중이다. Google지도 API를 올바르게 설치했습니다. 지도가 나타납니다. 나는 또한 에뮬레이터가 Google API인지 확인했다. 내 코드를 테스트하고 geocoder.getFromLocationName이 null을 반환합니다. 나는이 질문을 보았고 다른 해결책을 시도했지만 아무도 효과가 없었다. 여기 내 코드가있다.geocoder.getFromLocationName이 에뮬레이터에서 작동하지 않습니까?
public class GetURL extends MapActivity {
Geocoder geocoder;
MapView mapView = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView)findViewById(R.id.geoMap);
mapView.setBuiltInZoomControls(true);
int lat = (int)(30.334954*1000000);
int lng = (int)(-81.5625*1000000);
GeoPoint pt = new GeoPoint(lat,lng);
mapView.getController().setZoom(10);
mapView.getController().setCenter(pt);
mapView.getController().animateTo(pt);
geocoder = new Geocoder(this);
}
public void first_location(View arg0) {
try {
EditText loc = (EditText)findViewById(R.id.location);
String locationName = loc.getText().toString();
List<Address> addressList =
geocoder.getFromLocationName(locationName, 5);
if(addressList!=null && addressList.size()>0)
{
int lat = (int)(addressList.get(0).getLatitude()*1000000);
int lng = (int)(addressList.get(0).getLongitude()*1000000);
GeoPoint pt = new GeoPoint(lat,lng);
mapView.getController().setZoom(15);
mapView.getController().setCenter(pt);
mapView.getController().animateTo(pt);
}
} catch (IOException e) {
e.printStackTrace();
}
}
감사합니다. 2.2에서 테스트하고 있습니다. – Aaron