简体   繁体   English

是否可以在Android Google Maps API v2中使用街景视图上的标记?

[英]Is it possible to use markers on street view in android Google maps API v2?

我在我的应用程序中实现了街景,我希望在街景中看到地图标记,这可能吗?

It's possible to add markers to StreetView in Android via a custom implementation. 可以通过自定义实现向Android中的StreetView添加标记。

You should put a transparent SurfaceView on top of your StreetView , 您应该在StreetView上放置一个透明的SurfaceView

Pass panorama. 通过全景。 setOnStreetViewPanoramaCameraChangeListener (..) and panorama. setOnStreetViewPanoramaCameraChangeListener (..)和全景图。 setOnStreetViewPanoramaCameraChangeListener (..) to your surface view to update camera position and location . setOnStreetViewPanoramaCameraChangeListener (..)到表面视图以更新摄像机位置位置

Then calculate distance to the marker from your camera location, and azimuth from you to the marker. 然后计算从相机位置标记的距离方位和从你的标记。

Lastly calculate projection of those values to the screen - get view height, view width, etc. from your surface view, and draw your markers' bitmap to surface view's canvas . 最后计算这些值到屏幕的投影 - 从表面视图获取视图高度,视图宽度等,并将标记的位图绘制到表面视图的画布

Save those bitmaps to a HashMap to avoid loading same bitmap multiple times. 将这些位图保存到HashMap以避免多次加载相同的位图。 This will make your draw thread run much faster. 这将使您的绘制线程运行得更快。 Later you will probably want to load markers' icons from your online source. 稍后您可能希望从在线来源加载标记的图标。

There's still going to be some delay and markers are going to tremble a bit, so smoothen their placement. 仍然会有一些延迟,标记会有点颤抖,所以平滑它们的位置。

Don't forget to save your markers screen projection left top right bottom placement in a HashMap to implement click on markers. 不要忘记将标记屏幕投影左上角的底部放置保存在HashMap中以实现单击标记。

You will then want to make them markers clickable . 然后,您将要使它们可以点击标记。

override onTouchEvent ( .. ) in SurfaceView. 在SurfaceView中覆盖onTouchEvent (..)。

Save the position from the latest motion event in some field, then return false to pass the touch event to the underlying StreetView. 在某些字段中保存最新动作事件的位置,然后返回false以将触摸事件传递给基础StreetView。

Implement panorama. 实现全景。 setOnStreetViewPanoramaClickListener ( .. ) in the upper level - pass the click event to the SurfaceView, and you will know your click's x/y position from the saved field. 上层的setOnStreetViewPanoramaClickListener (..) - 将click事件传递给SurfaceView,您将从保存的字段中知道点击的x / y位置。

Loop through your markers' saved On Screen Position HashMap to know whether some marker was really clicked , if yes - return that event to the final listener in the upper level, and you will know when a marker was clicked 循环浏览标记'已保存的屏幕位置HashMap以了解是否真的点击了某个标记,如果是 - 将该事件返回到上层的最终侦听器,您将知道何时单击标记

Check out the video to look how it turned out for my project - it took me 3 days to implement this feature [android] street view custom marker 查看视频 ,了解我的项目结果如何 - 我花了3天时间实现此功能[android]街景自定义标记

I can't provide code samples here, but be free to ask 我不能在这里提供代码示例,但可以随意提问

Nowadays Android Google maps API v2 can´t add markers, this option is only available for iOS. 如今Android Google maps API v2无法添加标记,此选项仅适用于iOS。

Markers within Street View https://developers.google.com/maps/documentation/ios/streetview#markers_within_street_view 街景视图中的标记 https://developers.google.com/maps/documentation/ios/streetview#markers_within_street_view

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM