【发布时间】: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