ユーザーに現在の場所を地図上に表示したい小さなAndroidアプリケーションを開発しています。そのため、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 値を使用しますが、出力に変化はありません。この問題を解決する解決策はありますか...助けが必要です...ありがとう...