I am trying to show maps in android using API v2.
I want Google material icon "my location" on map. But, whenever I try to add in layout, it does not reflect in output.
I am able to get maps without icon. I need icon to integrate with map.
When I write ImageButton code outside the fragment tag, icon displays in preview pane, but not inside it.
where should I put the ImageButton code?
code for Mylayout.xml:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent">
</fragment>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ic_gps"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:src="@drawable/ic_my_location_black_18dp" />
</RelativeLayout>
Get your map object (mMap) and call setMyLocationEnabled(boolean)
on it.
mMap.setMyLocationEnabled(true);
This will add the default image button that initiates a 'find my location' action.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.