2017-09-25 80 views
0

我开发了一个使用OSMDroid(开放街道地图)显示车辆位置等的车辆监控应用程序。一切正常。从我的应用程序转到Google Maps应用程序直接进入街景模式

但是,我试图这样做,当您在地图上按车辆时,它会自动打开Goog​​le地图,并使用车辆的GPS坐标立即进入街道视图。

我不能在我的应用程序中使用Google地图,因为它对商业应用程序来说不是免费的(至少,我的老板告诉过我,我必须使用OSMDroid)。我这样说只是因为我不希望你的答案是“只使用谷歌地图API” - 我知道我可以,但我不能。

所以解决方法是 - 将我的应用程序的GPS信息作为意图发送到平板电脑上已安装的Google地图应用程序。

下面是我使用的代码:

@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; 
} 

一切运作良好,并进入到谷歌地图应用程序,并指向车辆的位置 - 问题是,我还没有发现任何方式自动进入该特定位置的街景。

我发现这里的答案:

How to open a street view in virtual reality mode programmatically?

的代码做的正是这一个:

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

但是,我不知道什么是 “& CPB” 参数表示。

可能的答案在这里:https://productforums.google.com/forum/#!topic/maps/aBj7qc8j0BI

这是我的新代码 - 这一次,我只得到一个黑色的屏幕多数民众赞成继续加载:

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

回答

1
// 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

+0

这就是我什么已经做了,并且我得到了一个不断加载的黑屏。 也许车辆在谷歌相机还没有的地方?这在奥地利的某个地方。 –

+0

然后你尝试过与另一个位置? –

+0

我已经硬编码了一个从浏览器中取得的新位置,它起作用。让我检查一下问题是信息传递的方式,还是仅仅意味着采用街景图像的谷歌车辆并不是我车辆的位置,这就是为什么它没有加载。 –

相关问题