Manish
Manish

Reputation: 1279

Google Map app getting crash while opening from my app

With the help of following code i am trying to open Google map application but its getting crash after 2 min of loading.

Code snippet :

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);

Note : input from my side is fine and i am not getting any logs regarding this.

Upvotes: 0

Views: 844

Answers (2)

Anurag
Anurag

Reputation: 1038

The first diagnostic is to wrap your code inside a try{}catch{} block

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

And then write the exception into a log file or any any other way. This will allow to be sure that the issue is caused by any thrown error in the code or else it could also be a problem with the resources on the device. If you're testing on an emulator, then try to increase the resources on the device. Also try to fetch the debugger response through ADB.

Upvotes: 0

Naveen Tamrakar
Naveen Tamrakar

Reputation: 3339

try using this way also added permission

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

Upvotes: 1

Related Questions