Eclipseのエミュレーターを使用してAndroidで最初のGoogleマップを作成しようとしていますが、成功しません。マップで取得できるのは、ズームできる灰色のタイル画面だけですが、そこにはマップがありません。以下は私のAndroidManifest
ファイルです:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.herb2"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="17" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.example.mapdemo.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<uses-library android:name="com.google.android.maps" />
<activity
android:name="com.example.herb2.Herb2Activity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="my key is not shown here" />
</manifest>
以下は私のレイアウトファイルです:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >
<TextView
android:id="@+id/latitude_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Latitude: " />
<TextView
android:id="@+id/longitude_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Longitude: " />
<com.google.android.maps.MapView
android:id="@+id/mapvw"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:apiKey="my key is not shown here"
android:clickable="true"
android:enabled="true" />
</LinearLayout>
最後に、私のJavaソースを以下に示します。
public class Herb2Activity extends MapActivity {
private TextView latitudeView;
private TextView longitudeView;
private LocationManager locationManager;
private MapController mapController;
private MapView mapView;
private GeoPoint point;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_herb2);
latitudeView = (TextView) findViewById(R.id.latitude_view);
longitudeView = (TextView) findViewById(R.id.longitude_view);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
mapView = (MapView) findViewById(R.id.mapvw);
mapView.setBuiltInZoomControls(true);
mapView.setSatellite(true);
mapController = mapView.getController();
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
3600, 1000, new LocationListener() {
public void onProviderDisabled(String provider) {
}
public void onProviderEnabled(String provider) {
}
public void onStatusChanged(String provider, int status,
Bundle extras) {
}
public void onLocationChanged(Location loc) {
if (loc != null) {
int lt = (int) (loc.getLatitude());
int lg = (int) (loc.getLongitude());
latitudeView.setText("Latitude is: "
+ String.valueOf(lt));
longitudeView.setText("Longitude is: "
+ String.valueOf(lg));
int latit = (int) (loc.getLatitude() * 1E6);
int longit = (int) (loc.getLongitude() * 1E6);
point = new GeoPoint(latit, longit);
mapController.animateTo(point);
mapController.setZoom(15);
}
}
});
}
@Override
protected boolean isRouteDisplayed() {
return true;
}
@Override
protected boolean isLocationDisplayed() {
return false;
}
}
Googleから生成したAPIキーと関係があるのではないかと思います。キーを生成するためにSHA1証明書のフィンガープリントを提供しました。キーの最後に、上記のようなパッケージ名を追加しましたcom.example.herb2
。また、エミュレーターとしてGoogleAPIデバイスを使用していることを確認しました。MD5フィンガープリントが本番環境で使用されていると思います。私の地図が灰色しか表示されない理由について助けていただければ幸いです。