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

无人久伴 提交于 2019-12-10 16:27:47

问题


I implemented the street view in my app and i want to see the map markers in street view, it is possible?


回答1:


Nowadays Android Google maps API v2 can´t add markers, this option is only available for iOS.

Markers within Street View https://developers.google.com/maps/documentation/ios/streetview#markers_within_street_view




回答2:


It's possible to add markers to StreetView in Android via a custom implementation.

You should put a transparent SurfaceView on top of your StreetView,

Pass panorama.setOnStreetViewPanoramaCameraChangeListener(..) and panorama.setOnStreetViewPanoramaCameraChangeListener(..) to your surface view to update camera position and location.

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. 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.

You will then want to make them markers clickable.

override onTouchEvent( .. ) in SurfaceView.

Save the position from the latest motion event in some field, then return false to pass the touch event to the underlying 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.

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

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

I can't provide code samples here, but be free to ask



来源:https://stackoverflow.com/questions/25879529/is-it-possible-to-use-markers-on-street-view-in-android-google-maps-api-v2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!