私は ExtendedMapView と呼ばれる拡張 MapView クラスを使用しています。これには、MapView に沿って currentLocation も含まれます。ただし、このクラスはキャリブレーション時にクラッシュします。
これは、クラッシュを引き起こす MapActivity クラスの一部です。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
map=(ExtendedMapView)findViewById(R.id.map_view);}
ExtendedMapView クラス:
package com.sit.augmented_reality.map;
import android.content.Context;
import android.location.Location;
import com.google.android.maps.MapView;
public class ExtendedMapView extends MapView {
private Location currentLocation;
public ExtendedMapView(Context context, String apiKey) {
super(context, apiKey);
}
public void setCurrentLocation (Location location)
{
currentLocation = location;
}
public Location getCurrentLocation ()
{
return currentLocation;
}
}
レイアウト XML (map.xml):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.sit.augmented_reality.map.ExtendedMapView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:id="@+id/map_view"
android:apiKey="0zGaDxZvhGnutaf58dLLydh5riLex42FsZ7UKcA" />
</RelativeLayout>