google maps - Current Location button is not showing -


i using google map v2 in android app tab(viewpager) , want show current location in map couldn't find button.

addmasjid.java

package com.example.saroosh.masjidnow.tabs;  import android.support.annotation.nullable; import android.support.v4.app.fragment; import android.os.bundle; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup;  import com.example.saroosh.masjidnow.r; import com.google.android.gms.maps.cameraupdatefactory; import com.google.android.gms.maps.googlemap; import com.google.android.gms.maps.mapfragment; import com.google.android.gms.maps.mapview; import com.google.android.gms.maps.mapsinitializer; import com.google.android.gms.maps.onmapreadycallback; import com.google.android.gms.maps.model.latlng; import com.google.android.gms.maps.model.markeroptions;  public class addmasjid extends fragment implements onmapreadycallback{      mapview gmapview;     googlemap gmap = null;      @override     public view oncreateview(layoutinflater inflater, @nullable viewgroup container, @nullable bundle savedinstancestate) {         view v =inflater.inflate(r.layout.add_masjid,container,false);          gmapview = (mapview) v.findviewbyid(r.id.map);         gmapview.getmapasync(this);         gmapview.oncreate(savedinstancestate);         gmapview.onresume(); // needed map display         try {             mapsinitializer.initialize(getactivity().getapplicationcontext());         } catch (exception e) {             e.printstacktrace();         }          return v;     }       @override     public void onmapready(googlemap map) {         gmap = map;         gmap.setmaptype(googlemap.map_type_normal);         gmap.movecamera(cameraupdatefactory.newlatlngzoom(new                 latlng(0, 0), 0));          if (gmap != null) {             gmap.addmarker(new markeroptions().position(new latlng(0, 0)).title("marker"));             gmap.getuisettings().setmylocationbuttonenabled(true);        }     }     @override     public void onresume() {         super.onresume();         gmapview.onresume();      }      @override     public void onpause() {         super.onpause();         gmapview.onpause();      }      @override     public void ondestroy() {         super.ondestroy();         gmapview.ondestroy();     }      @override     public void onlowmemory() {         super.onlowmemory();         gmapview.onlowmemory();     }   }  

add_masjid.xml

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:orientation="vertical"     android:background="#000000">      <textview         android:id="@+id/textview1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignbaseline="@+id/edittext1"         android:layout_alignbottom="@+id/edittext1"         android:layout_alignparentstart="true"         android:text="@string/xyz"         android:textcolor="#ffffff"         android:textsize="20sp"         />      <button         android:id="@+id/generalid"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentend="true"         android:layout_alignparenttop="true"         android:background="@drawable/rect1"         android:onclick="geolocate"         android:text="@string/abc"         android:textcolor="#ffffff"         android:textsize="20sp" />      <edittext         android:id="@+id/edittext1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_toendof="@+id/textview1"         android:layout_tostartof="@+id/generalid"         android:ems="10"         android:inputtype="text"         android:background="#ffffff"         android:labelfor="@+id/edittext1"         android:layout_above="@+id/map"         android:layout_alignparenttop="true" />      <com.google.android.gms.maps.mapview         android:id="@+id/map"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:layout_below="@+id/generalid">      </com.google.android.gms.maps.mapview>      <!--<fragment-->         <!--android:id="@+id/map"-->         <!--android:name="com.google.android.gms.maps.supportmapfragment"-->         <!--android:layout_width="match_parent"-->         <!--android:layout_height="wrap_content"-->         <!--android:layout_alignparentbottom="true"-->         <!--android:layout_below="@+id/generalid" />-->  </relativelayout> 

please guide me how can button in app.

i have solved problem adding code in it, this.

@override     public void onmapready(googlemap map) {         gmap = map;         gmap.setmaptype(googlemap.map_type_normal);         gmap.movecamera(cameraupdatefactory.newlatlngzoom(new                 latlng(0, 0), 0));           if (gmap != null) {             gmap.addmarker(new markeroptions().position(new latlng(0, 0)).title("marker"));             if (activitycompat.checkselfpermission(getactivity().getapplicationcontext()                     , manifest.permission.access_fine_location) != packagemanager.permission_granted && activitycompat.checkselfpermission(getactivity().getapplicationcontext()                     , manifest.permission.access_coarse_location) != packagemanager.permission_granted) {                 // todo: consider calling                 //    activitycompat#requestpermissions                 // here request missing permissions, , overriding                 //   public void onrequestpermissionsresult(int requestcode, string[] permissions,                 //                                          int[] grantresults)                 // handle case user grants permission. see documentation                 // activitycompat#requestpermissions more details.                 return;             }             gmap.setmylocationenabled(true);             gmap.getuisettings().setmylocationbuttonenabled(true);           }     } 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -