Is it possible to use markers on street view in an

2019-06-28 05:27发布

问题:

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