I have developed a vehicle monitoring application that uses OSMDroid (Open Street Maps) to display the vehicle location and so on. Everything works fine.
However, I'm trying to make it such that when you press on a vehicle on the map, it automatically opens up Google Maps and, using the GPS coordinates of the vehicle, gets into street view immediately.
I cannot use Google Maps in my application because it's not free for business applications (at least, my boss told me that and I had to work with OSMDroid). I'm saying this simply because I don't want your answers to be "just use the google maps API" - I know I could, but I can't.
So the solution is - send the GPS information from my application as an intent to the Google Maps application that's already installed on the tablet.
Here's the code that I use:
@Override
public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
//on a tap on the bus map indicator, go to google maps in the particular location of the bus
Uri uri = Uri.parse("geo:"+gpsLatitude[0]+","+gpsLongitude[0]+"?z=" + map.getZoomLevel());
//set the data for the intent as the created uri
Intent intent = new Intent(Intent.ACTION_VIEW,uri);
//go to the location of the bus
startActivity(intent);
return true;
}
Everything works well, and it goes to the Google Maps application and points to the location of the vehicle - the problem is, I haven't found any way to automatically get into street view at that particular location.
I found an answer here:
How to open a street view in virtual reality mode programmatically?
The code to do it is this one:
Intent streetView = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("google.streetview:cbll=27.173891,78.042068" + "&cbp=1,90,,0,1.0&mz=8"));
startActivity(streetView);
However, I'm not sure what the "&cpb" parameters represent.
Possible answer here: https://productforums.google.com/forum/#!topic/maps/aBj7qc8j0BI
Here's my new code - this time, I only get a black screen that's continuously loading:
@Override
public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
//on a tap on the bus map indicator, go to street view in the particular location of the bus
Uri googleMapsUri = Uri.parse("google.streetview:cbll="+gpsLatitude[0]+","+gpsLongitude[0]);
//set the data for the intent as the created uri
Intent mapIntent = new Intent(Intent.ACTION_VIEW,googleMapsUri);
// specify the google maps package
mapIntent.setPackage("com.google.android.apps.maps");
//go to the location of the bus
startActivity(mapIntent);
return true;
// Create a Uri from an intent string. Use the result to create an Intent.
Uri gmmIntentUri = Uri.parse("google.streetview:cbll=46.414382,10.013988");
// Create an Intent from gmmIntentUri. Set the action to ACTION_VIEW
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
// Make the Intent explicit by setting the Google Maps package
mapIntent.setPackage("com.google.android.apps.maps");
// Attempt to start an activity that can handle the Intent
startActivity(mapIntent);
https://developers.google.com/maps/documentation/urls/android-intents