android - How to add SurfaceView on top of Google Map Streetview? -
how can display surfaceview on streetmaps view , draw bitmap on surfaceview? surfacecreated() override method not being called.
here surfaceview class
public class streetviewoverlay extends surfaceview implements surfaceholder.callback { bitmap mbitmap; context mcontext; public streetviewoverlay(context context, int bitmap) { super(context); mbitmap = bitmapfactory.decoderesource(getresources(), bitmap); this.mcontext = context; } public streetviewoverlay(context context) { super(context); } public streetviewoverlay(context context, attributeset attrs) { super(context, attrs); } public streetviewoverlay(context context, attributeset attrs, int defstyleattr) { super(context, attrs, defstyleattr); } @override public void surfacecreated(surfaceholder holder) { canvas canvas = null; try { canvas = holder.lockcanvas(null); synchronized (holder) { ondraw(canvas); } } catch (exception e) { e.printstacktrace(); } { if (canvas != null) { holder.unlockcanvasandpost(canvas); } } } @override public void surfacechanged(surfaceholder holder, int format, int width, int height) { } @override public void surfacedestroyed(surfaceholder holder) { } @override protected void ondraw(canvas canvas) { canvas.drawcolor(color.transparent); canvas.drawbitmap(mbitmap, 30, 30, new paint()); } }
inside of fragment, displaying streetmap view this
@override public void onstreetviewpanoramaready(streetviewpanorama streetviewpanorama) { if (streetviewpanorama != null) { // instantiate street view panorama object mstreetviewpanorama = streetviewpanorama; // set user navigation enabled false mstreetviewpanorama.setusernavigationenabled(false); // set onstreetviewpanoramachangelistener mstreetviewpanorama.setonstreetviewpanoramachangelistener(new streetviewpanorama.onstreetviewpanoramachangelistener() { @override public void onstreetviewpanoramachange(streetviewpanoramalocation streetviewpanoramalocation) { if (streetviewpanoramalocation != null && streetviewpanoramalocation.links != null) { // location available streetviewpanoramacamera camera = new streetviewpanoramacamera.builder() .bearing((float) (sphericalutil.computeheading (mstreetviewpanorama.getlocation().position, latlng))) .build(); // set street view camera face stop mstreetviewpanorama.animateto(camera, 150); } } }); } }
in oncreateview() of fragment instantiate surfaceview overlay
streetviewoverlay streetviewoverlay = new streetviewoverlay(mcontext, r.drawable.ic_launcher);
my xml looks this
<!-- street view --> <fragment android:id="@+id/frag_streetview" class="com.google.android.gms.maps.supportstreetviewpanoramafragment" android:layout_width="match_parent" android:layout_height="match_parent"/> <com.example.utilities.map.streetviewoverlay android:id="@+id/street_overlay" android:layout_height="match_parent" android:layout_width="match_parent"/>
Comments
Post a Comment