지도에서 현재 위치를 사용자에게 보여주고 싶은 작은 안드로이드 응용 프로그램을 개발 중입니다. 그런 이유로 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 : ... 도움이 필요이 문제 ... 가 감사를 해결하기 위해 어떤 솔루션 ... 당신이지도를 다운로드 할 수없는 경우
을 같이
또한, 실제 장치에 그것을 시도? – 10101010
오랜 시간 기다렸지 만 작동하지 않습니다 ... ( – nilkash
오류가 발생합니다 ** 연결 팩토리 클라이언트를 얻을 수 없습니다 ** – nilkash