【问题标题】:Go from my application to the Google Maps application directly into the street view mode从我的应用程序到谷歌地图应用程序直接进入街景模式
【发布时间】:2017-09-25 13:53:47
【问题描述】:

我开发了一个车辆监控应用程序,它使用 OSMDroid(Open Street Maps)来显示车辆位置等。一切正常。

但是,我正在努力做到这一点,当您在地图上按下车辆时,它会自动打开 Google 地图,并使用车辆的 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;
}

一切正常,它会转到 Google 地图应用程序并指向车辆的位置 - 问题是,我还没有找到任何方法可以自动进入该特定位置的街景。

我在这里找到了答案:

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;

【问题讨论】:

    标签: android google-maps gps


    【解决方案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

    【讨论】:

    • 这就是我已经在做的事情,我得到一个不断加载的黑屏。也许车辆在谷歌相机尚未出现的地方?这是在奥地利的某个地方。
    • 我已经硬编码了一个从浏览器获取的新位置,它可以工作。让我检查一下问题是信息传递的方式,还是仅仅意味着拍摄街景图像的谷歌车辆不在我的车辆所在的位置,这就是它没有加载的原因。
    • 确实,问题在于车辆所在的地方谷歌地图没有街景。我在“更公共的地方”找到了一个,它有效。感谢您的帮助!
    猜你喜欢
    • 2015-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-15
    相关资源
    最近更新 更多