私のコードは別々ですが、統合するとクラッシュします!
この部分は、現在の値をハードコーディングすると機能します
Intent is = new Intent(android.content.Intent.ACTION_VIEW,Uri.parse("http://maps.googleapis.com/maps/api/staticmapcenter="+current+"&zoom=11&size=600000x400000&maptype=roadmap&markers=color:blue%7Clabel:A%7C49.264081,-123.170326&markers=color:green%7Clabel:B%7C49.227741,-122.997605&markers=color:yellow%7Clabel:C%7C49.322642,-123.099007&markers=color:purple%7Clabel:E%7C49.267501,-123.000693&markers=color:red%7Ccolor:red%7Clabel:D%7C49.193767,-123.083017&sensor=false"));
startActivity(is);
この部分は機能し、現在の場所を提供します
googlemap.setMyLocationEnabled(true);
LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE);
String provider = lm.getBestProvider(new Criteria(), true);
Log.v(provider, "this is provider");
if (provider == null){
onProviderDisabled(provider);
}
Location loc = lm.getLastKnownLocation(provider);
Log.v(loc.toString(),"this is loc");
if(loc != null) {
onLocationChanged(loc);
しかし、これは統合であり、クラッシュします
googlemap.setMyLocationEnabled(true);
LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE);
String provider = lm.getBestProvider(new Criteria(), true);
Log.v(provider, "this is provider");
if (provider == null){
onProviderDisabled(provider);
}
Location loc = lm.getLastKnownLocation(provider);
Log.v(loc.toString(),"this is loc");
if(loc != null) {
onLocationChanged(loc);
String current= loc.toString();
Intent is = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://maps.googleapis.com/maps/api/staticmap?center="+current+"&zoom=11&size=600000x400000&maptype=roadmap&markers=color:blue%7Clabel:A%7C49.264081,-123.170326&markers=color:green%7Clabel:B%7C49.227741,-122.997605&markers=color:yellow%7Clabel:C%7C49.322642,-123.099007&markers=color:purple%7Clabel:E%7C49.267501,-123.000693&markers=color:red%7Ccolor:red%7Clabel:D%7C49.193767,-123.083017&sensor=false"));
startActivity(is);
LOGCAT: 04-04 20:58:34.765: W/dalvikvm(1082): threadid=11: キャッチされない例外で終了するスレッド (group=0x40a71930) 04-04 20:58:34.805: E/AndroidRuntime(1082): FATAL EXCEPTION : AsyncTask #1 04-04 20:58:34.805: E/AndroidRuntime(1082): java.lang.RuntimeException: doInBackground() の実行中にエラーが発生しました 04-04 20:58:34.805: E/AndroidRuntime(1082): android.os.AsyncTask$3.done(AsyncTask.java:299) 04-04 20:58:34.805: E/AndroidRuntime(1082): java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352) 04 -04 20:58:34.805: E/AndroidRuntime(1082): java.util.concurrent.FutureTask.setException(FutureTask.java:219) 04-04 20:58:34.805: E/AndroidRuntime(1082): Java で.util.concurrent.FutureTask.run(FutureTask.java:239) 04-04 20:58:34.805: E/AndroidRuntime(1082): android.os.AsyncTask$SerialExecutor$1 で。実行 (AsyncTask.java:230) 04-04 20:58:34.805: E/AndroidRuntime(1082): java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 04-04 20:58:34.805: E/AndroidRuntime(1082): java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 04-04 20:58:34.805: E/AndroidRuntime(1082): java.lang.Thread.run で(Thread.java:856) 04-04 20:58:34.805: E/AndroidRuntime(1082): 原因: java.lang.NullPointerException 04-04 20:58:34.805: E/AndroidRuntime(1082): com. example.distancemap.MainActivity.ShowMap(MainActivity.java:94) 04-04 20:58:34.805: E/AndroidRuntime(1082): com.example.distancemap.MainActivity$TestGoogleMaps.doInBackground(MainActivity.java:67) 04 -04 20:58:34.805: E/AndroidRuntime(1082): com.example.distancemap.MainActivity$TestGoogleMaps.doInBackground(MainActivity.java:1) 04-04 20:58:34.805: E/AndroidRuntime(1082): android.os.AsyncTask$2.call(AsyncTask.java:287) 04-04 20:58:34.805: E/AndroidRuntime(1082): at java.util.concurrent.FutureTask.run(FutureTask.java:234) 04-04 20:58:34.805: E/AndroidRuntime(1082): ... 4 もっと見る