我的代码分开但在我集成时崩溃!
如果我硬编码当前的值,这部分工作
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): at com. example.distancemap.MainActivity.ShowMap(MainActivity.java:94) 04-04 20:58:34.805: E/AndroidRuntime(1082): at 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):在 java.util.concurrent.FutureTask.run(FutureTask.java:234) 04-04 20:58:34.805: E/AndroidRuntime(1082): ... 4 更多