2012-02-22 2 views
0

나는 사용자가 입력 한 다음 사용자가 입력 한지도를 중앙에 배치하는 앱을 개발 중이다. 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(); 

    } 

} 

답변

0

어떤 API 버전을 테스트하고 있습니까? 이전 안드로이드 버전에서 버그가 수 있도록이 나타납니다 또한 Geocoder works in 1.6 but not in 2.2 emulator

앱이 인터넷 권한을 항상 같은 위치 기능을 테스트하기 위해 실제 장치를 사용

(나는지도가지도 타일을 표시로이하는 가정)이 있는지 확인 나는 그것을 훨씬 쉽게, 그리고 현실 세계의 시나리오에 가깝다.

지오 코더 기능은 공식 Android 기기 (마켓/Gmail /지도 등)에서만 사용할 수 있습니다. Android 마켓이없는 저렴한 Android 기기는 지오 코드 결과를 제공하지 못합니다.

+0

감사합니다. 2.2에서 테스트하고 있습니다. – Aaron

4

앱이 실제 기기에서 작동하는 경우 코드가 정상적으로 작동해야합니다. 지오 코딩은 기업에서 장치에 가입하거나 구매해야하는 서비스로 생각하십시오. 나는 그들 대부분이 단지 구글을 사용한다고 생각하지만, 빙 (Bing)이나 기타 다른 것들도 사용할 수있을 것이다.

the docs에서

:

지오 코더 클래스는 핵심 안드로이드 프레임 워크에 포함되지 않은 백엔드 서비스를 필요로한다. 플랫폼에 백엔드 서비스가 없으면 지오 코더 쿼리 메서드는 빈 목록을 반환합니다. isPresent() 메서드를 사용하여 지오 코더 구현 이 있는지 여부를 확인하십시오. 에뮬레이터에서 geocoder.isPresent()를 호출 내 경험에

는 false를 반환합니다, 진짜 전화에서 한 실제 전화가 당신이 들었어요 회사에 의해 이루어집니다로, true를 돌려줍니다.

작업/백업 서비스를 원할 경우 웹 페이지에서와 마찬가지로 HTTP를 통해 Google Maps API을 쿼리 할 수 ​​있습니다. 이 대답의 예가 here입니다.

관련 문제