2013-01-03 3 views
2

지도에서 현재 위치를 사용자에게 보여주고 싶은 작은 안드로이드 응용 프로그램을 개발 중입니다. 그런 이유로 Google지도 API를 사용하고 있습니다. 나는지도 api 열쇠를 얻기를위한 모든 필요한 체제를 따른다. 위치 < .android/debug.keystore>에 기본 키 저장소가 있습니다. SHA1 키와 MD 5 키와 같은 키에서 필요한 모든 값을 얻습니다. Google API 콘솔에서 SHA1 + package_name을 사용하여 API 키를 얻습니다. 또한 Google지도 API v2 서비스를 사용할 수 있습니다.안드로이드지도는지도보기를 보이지 않습니다.

내 프로젝트 측면에서 나는 다음 일을했다.

// in main.xml 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <TextView 
    android:id="@+id/myLocationText" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
     android:text="@string/hello_world" 
    tools:context=".WhereAmI" /> 

    <com.google.android.maps.MapView 
     android:id="@+id/myMapView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:enabled="true" 
     android:clickable="true" 
     android:apiKey="AIzaSyD6EHgxObm01ooCF9DsMzOppJbNp8O2_j4" 
    /> 

</LinearLayout> 


// In manifest file 

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 
<uses-permission android:name="android.permission.ACCESS_LOCATION"/> 
<uses-permission android:name="android.permission.ACCESS_GPS"/> 
<uses-permission android:name="android.permission.INTERNET"/> 

<uses-library android:name="com.google.android.maps"/> 

//mapactivity.......... 
public class mapview extends MapActivity { 

    private MapController mapController; 

    @Override 
    protected boolean isRouteDisplayed() { 
    return false; 
    } 

    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) 
     { 

     } 
     }; 
     LocationManager locationManager; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    MapView myMapView = (MapView)findViewById(R.id.myMapView); 
    mapController = myMapView.getController(); 
    myMapView.setSatellite(true); 
    myMapView.setBuiltInZoomControls(true); 
    mapController.setZoom(17); 

    //LocationManager locationManager; 
    String svcName = Context.LOCATION_SERVICE; 
    locationManager = (LocationManager)getSystemService(svcName); 

    Criteria criteria = new Criteria(); 
    criteria.setAccuracy(Criteria.ACCURACY_FINE); 
    criteria.setPowerRequirement(Criteria.POWER_LOW); 
    criteria.setAltitudeRequired(false); 
    criteria.setBearingRequired(false); 
    criteria.setSpeedRequired(false); 
    criteria.setCostAllowed(true); 
    String provider = locationManager.getBestProvider(criteria, true); 

    //dis(provider); 
    //Location l = locationManager.getLastKnownLocation(locationManager.NETWORK_PROVIDER); 
    Location l = locationManager.getLastKnownLocation(provider); 

    updateWithNewLocation(l); 

    locationManager.requestLocationUpdates(provider, 2000, 10, locationListener); 

    } 


    private void updateWithNewLocation(Location location) 
    { 
     TextView myLocationText; 
     myLocationText = (TextView)findViewById(R.id.myLocationText); 
     String latLongString = "No location found"; 
     String addressString = " No address found"; 
     //Toast.makeText(this, "inside update location", Toast.LENGTH_SHORT).show(); 

     if (location != null) 
     { 
      double lat = location.getLatitude(); 
      double lng = location.getLongitude(); 
      latLongString = "Lat:" + lat + "\nLong:" + lng; 
      Geocoder gc = new Geocoder(this, Locale.getDefault()); 
      Double geoLat = location.getLatitude()*1E6; 
      Double geoLng = location.getLongitude()*1E6; 
      GeoPoint point = new GeoPoint(geoLat.intValue(),geoLng.intValue()); 
      mapController.animateTo(point); 

      try { 
       List<Address> addresses = gc.getFromLocation(lat, lng, 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); 

     } 

    } 

    @Override 
    public void onDestroy() 
    { 
    super.onDestroy(); 
    locationManager.removeUpdates(locationListener); 
    } 

} 

지금 내 문제는 내가 에뮬레이터 또는 장치에이 응용 프로그램을 실행할 때 그것은 나에게 적절한 좌표와 위치 만지도보기를 표시하지를 제공한다는 것입니다. 회색 그리드보기 만 표시됩니다. 거기에 같은 문제에 관한 중복 질문이 많이 있다는 것을 알고 있지만 여전히 나는이 문제를 빠져 나올 수 없습니다. 나는 또한 사용자 정의 디버그 키를 만들고 해당 키의 SHA1 값을 사용하지만 출력은 변경하지 않습니다.

1 : ... 도움이 필요이 문제 ... 가 감사를 해결하기 위해 어떤 솔루션 ... 당신이지도를 다운로드 할 수없는 경우

+0

을 같이

또한, 실제 장치에 그것을 시도? – 10101010

+0

오랜 시간 기다렸지 만 작동하지 않습니다 ... ( – nilkash

+0

오류가 발생합니다 ** 연결 팩토리 클라이언트를 얻을 수 없습니다 ** – nilkash

답변

1

것은, 두 문제 중 하나가 될 수 있는가) 당신은 더 이상 사용되지 않는 API 버전을 사용하고 있습니다. 2) 인터넷 연결 속도가 빠릅니다.

표시된 코드는 API v1을 사용하며 API v2의 키를 사용합니다. 나는 그것이 작동하지만 v2의 키로 API v2를 사용하면 확실히 작동하는지 잘 모르겠습니다. 여기를 봐 here. 또한 Mapview 대신 조각을 사용하십시오. 에뮬레이터는 몇 가지 문제가 있기 때문에 충분히 좋은 인터넷의 속도가지도 타일을 다운로드하는 것입니다 here

+0

안녕하세요 rajat는 당신의 솔루션을 따르려고했습니다. 하지만 내 프로젝트에 Google Play 라이브러리를 추가하려고하면 안드로이드 프로젝트에 빨간색 마크가 표시됩니다. 프로젝트를 실행하려고하면 오류가있는 프로젝트에서 오류가 발생한다는 오류가 발생합니다. 하지만 내 프로젝트에 어떤 오류도 없었습니다. 심지어 mapdemo에 대한 안드로이드 sdk 폴더 샘플에서 샘플을 실행하려고했지만 동일한 문제가 발생했습니다. – nilkash

+0

그 문제를 해결하는 데 도움을 줄 수 있습니까? – nilkash

+0

[튜토리얼] (https://developers.google.com/maps/documentation/android/intro#sample_code)을 따르지만 내 프로젝트를 실행할 수 없습니다. 내 프로젝트에 오류가 없습니다. 하지만 여전히 작동하지 않습니다 ... :( – nilkash