Google マップ APIv2 を使用する Android 用のアプリを作成しています。ほぼすべてのデバイスで動作します。しかし、Android 4.0.4 と 4.2.2 には問題があります。マップの初期化中にアプリケーションがクラッシュします。
Android 4.0.4 では再起動後に動作しますが、4.2.2 では動作しません。
初期化のコードは次のとおりです。
public class MyMapActivity extends FragmentActivity implements LocationListener
{
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_map);
// Getting Google Play availability status
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());
// Showing status
if(status!=ConnectionResult.SUCCESS)
{ // Google Play Services are not available
int requestCode = 10;
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
dialog.show();
}
else
{// Google Play Services are available
// Getting reference to the SupportMapFragment of activity_main.xml
SupportMapFragment fm = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
// Getting GoogleMap object from the fragment
map = fm.getMap();
// Enabling MyLocation Layer of Google Map
map.setMyLocationEnabled(true);
}
}
}
activity_my_map.xml:
<RelativeLayout 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"
tools:context=".MainActivity" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>