谷歌地图应用程序从我的应用程序打开时崩溃

时间:2015-01-16 06:22:49

标签: android google-maps android-intent

在以下代码的帮助下,我正在尝试打开Goog​​le地图应用程序,但是在加载2分钟后它会崩溃。

代码段:

String url = "http://maps.google.com/maps?saddr="
                    + GPS_Data.getLatitude() + "," + GPS_Data.getLongitude()
                    + "&daddr=" + mCompanyDetail.getLatitude() + ","
                    + mCompanyDetail.getLongitude() + "&mode=driving";
            Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(url));
            intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
            startActivity(intent);

注意:从我这边输入很好,我没有得到任何关于此的日志。

2 个答案:

答案 0 :(得分:1)

尝试使用这种方式还添加了权限

double latitude = 40.714728;
double longitude = -73.998672;
String label = "ABC Label";
String uriBegin = "geo:" + latitude + "," + longitude;
String query = latitude + "," + longitude + "(" + label + ")";
String encodedQuery = Uri.encode(query);
String uriString = uriBegin + "?q=" + encodedQuery + "&z=16";
Uri uri = Uri.parse(uriString);
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, uri);
startActivity(intent);

Reference

答案 1 :(得分:0)

第一个诊断是将代码包装在try{}catch{}

try {
     ...
} catch (Exception e) {
     // This will catch any exception, because they are all descended from Exception
}

然后将异常写入日志文件或任何其他方式。这样可以确保问题是由代码中的任何抛出错误引起的,否则它也可能是设备上资源的问题。如果您在模拟器上进行测试,请尝试增加设备上的资源。还尝试通过ADB获取调试器响应。