私は位置情報サービスの基本を学び、位置をマークするために「ピン」を配置しようとしています。
これが最善のアプローチなのか、それとも代替案が何なのかはわかりません。これを行うためのより良い、またはより簡単な方法は何でしょうか?または、標準的な方法は何ですか?
さらに、このアプリをICS 4.0.3で実行すると、数分後に電話がフリーズします。最初は正常に動作し、場所が表示されますが、最終的にはデバイス全体が応答しなくなります。logcatとlast_kmsgの両方を確認しましたが、これを引き起こしている原因についてのヒントが見つかりません。Gingerbread 2.3.6は問題なくコードを実行します(少なくとも15分以上クラッシュしませんでしたが、ICSは1〜5分以内にクラッシュします)。
例外ではないようですが、これはメモリリークまたはカーネルパニックの可能性がありますか?これのデバッグを開始する方法がわかりません:\
どんな助けでもいただければ幸いです!
私は次のコードを使用しています:
Mapper.java:
public class Mapper extends MapActivity{
MapView mapView;
LocationManager lm;
LocationListener ll;
GeoPoint p;
MapController mc;
MapOverlay overlay;
List<Overlay> lol;
public void onCreate(Bundle x){
super.onCreate(x);
setContentView(R.layout.mapper);
mapView = (MapView)findViewById(R.id.mapView);
mapView.setBuiltInZoomControls(true);
mc = mapView.getController();
lol = mapView.getOverlays();
overlay = new MapOverlay();
lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
ll = new MyLocationListener();
mapView.invalidate();
}
private class MyLocationListener implements LocationListener{
public void onLocationChanged(Location loc){
if(loc!=null){
int lat = (int)(loc.getLatitude() * 1E6);
int lon = (int)(loc.getLongitude() * 1E6);
p = new GeoPoint(lat,lon);
mc.animateTo(p);
mc.setZoom(18);
lol.clear();
lol.add(overlay);
}
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
public void onResume(){
super.onResume();
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, ll);
}
public void onPause(){
super.onPause();
lm.removeUpdates(ll);
}
protected boolean isRouteDisplayed(){
return false;
}
private class MapOverlay extends com.google.android.maps.Overlay{
public boolean draw(Canvas canvas, MapView mv, boolean shadow, long when){
super.draw(canvas, mv, shadow);
Point sp = new Point();
mv.getProjection().toPixels(p, sp);
Bitmap pic = BitmapFactory.decodeResource(getResources(), R.drawable.image1);
canvas.drawBitmap(pic, sp.x, sp.y, null);
canvas.drawBitmap(pic, sp.x+60, sp.y, null);
canvas.drawBitmap(pic, sp.x-60, sp.y, null);
canvas.drawBitmap(pic, sp.x, sp.y+60, null);
canvas.drawBitmap(pic, sp.x, sp.y-60, null);
return true;
}
}
}
mapper.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.google.android.maps.MapView
android:id="@+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="mykeyworks"
android:clickable="true" />
</LinearLayout>
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jinworld"
android:versionCode="1"
android:versionName="1.0" android:installLocation="auto">
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>"
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<uses-library android:name="com.google.android.maps" />
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SecondActivity"
android:label="Second Activity" >
<intent-filter>
<action android:name="com.jinworld.SecondActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Notify"
android:label="DEVELOPERS" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Mapper"
android:label="Locatio" >
<intent-filter>
<action android:name="com.jinworld.Mapper" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>