google maps - Cannot find user location: -


i think have done using google maps api v2 position not shown , camera doesn't changes position.

the map loads stays in 0,0 location , never moves.

in device, see gps signal looking position , have tested outside.

here code: mainactivity.java:

    public class mainactivity extends fragmentactivity implements locationsource,locationlistener, onmapclicklistener, onmylocationchangelistener     {           final int rqs_googleplayservices = 1;          private googlemap mymap;          private locationmanager lm;          public location mylocation;          public tipobusca busca;          private enum tipobusca {busca_parada, busca_localizacao_inicial, busca_localizacao, busca_endereco, busca_drag};          public string tiporequest;          private criteria mycriteria;          public textview textview;          public onmylocationchangelistener locationlistener;           @override          protected void oncreate(bundle savedinstancestate)          {                  super.oncreate(savedinstancestate);                  setcontentview(r.layout.activity_main);                      //define textview wich receive test messages                  textview = (textview) findviewbyid(r.id.textview1);                   // getting google play availability status                      int status = googleplayservicesutil.isgoogleplayservicesavailable(getbasecontext());                      // showing status                     if(status!=connectionresult.success)                     { // google play services not available                         int requestcode = 10;                         dialog dialog = googleplayservicesutil.geterrordialog(status, this, requestcode);                         dialog.show();                     }                     else                     {                               //defining fragment map                           fragmentmanager myfragmentmanager = getsupportfragmentmanager();                   supportmapfragment mysupportmapfragment = (supportmapfragment)myfragmentmanager.findfragmentbyid(r.id.map);                   mymap = mysupportmapfragment.getmap();                   mymap.setmylocationenabled(true);                   mymap.setindoorenabled(true);                   mymap.setmaptype(googlemap.map_type_normal);                   mymap.setlocationsource(this);                   //mymap.setonmylocationchangelistener(this);                   mymap.setonmylocationchangelistener((onmylocationchangelistener) locationlistener);                    mycriteria = new criteria();                   mycriteria.setaccuracy(criteria.accuracy_fine);                    lm = (locationmanager)getsystemservice(context.location_service);                                //lm.requestlocationupdates(0, 50.0f, mycriteria, this, null);                   lm.requestlocationupdates(250, 1, mycriteria, this, null);                    textview.settext("localizando usuário...");                   mylocation = mymap.getmylocation();                       }            }  @override public void onproviderdisabled(string provider) {     // todo auto-generated method stub  }  @override public void onproviderenabled(string provider) {     // todo auto-generated method stub  }  @override public void onstatuschanged(string provider, int status, bundle extras) {     // todo auto-generated method stub  }  @override public void activate(onlocationchangedlistener listener) {     // todo auto-generated method stub  }  @override public void deactivate() {     // todo auto-generated method stub  }  @override public void onmapclick(latlng point) {     // todo auto-generated method stub     mymap.animatecamera(cameraupdatefactory.newlatlng(point)); }  @override public void onmylocationchange(location location) {     // todo auto-generated method stub     log.i("onmylocationchanged", "my location changed");     latlng latlng= new latlng(location.getlatitude(), location.getlongitude());     mymap.movecamera(cameraupdatefactory.newlatlng(latlng));     mymap.animatecamera(cameraupdatefactory.zoomto(15));     textview.settext("latitude:" +  location.getlatitude()  + ", longitude:" + location.getlongitude() ); }  @override public void onlocationchanged(location location) {     // todo auto-generated method stub     log.i("onlocationchanged", "location changed"); } } 

manifest:

      <?xml version="1.0" encoding="utf-8"?>       <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="mypackage" android:versioncode="1" android:versionname="1.0" >           <!-- setting permissions -->           <permission      android:name="mypackage.permission.maps_receive" android:protectionlevel="signature"></permission>           <uses-permission android:name="mypackage.permission.maps_receive"/>           <!-- setting versions requirements -->           <uses-sdk                    android:minsdkversion="8"                    android:targetsdkversion="17" />            <uses-permission android:name="android.permission.access_network_state"/>           <uses-permission android:name="android.permission.internet"/>           <uses-permission android:name="com.google.android.providers.gsf.permission.read_gservices"/>           <!-- external storage caching. -->           <uses-permission android:name="android.permission.write_external_storage"/>           <!-- location -->           <uses-permission android:name="android.permission.access_coarse_location"/>           <uses-permission android:name="android.permission.access_fine_location"/>           <!-- maps api needs opengl es 2.0. -->           <uses-feature                        android:glesversion="0x00020000"                        android:required="true"/>            <!-- setting icon application -->           <application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@android:style/theme.notitlebar" >                <meta-data android:name="com.google.android.maps.v2.api_key" android:value="myapikey_code_inserted_here"/>                <activity android:name="mypackage.mainactivity" >                   <intent-filter>                       <action android:name="android.intent.action.main" />                        <category android:name="android.intent.category.launcher" />                   </intent-filter>               </activity>           </application>        </manifest> 

if you're trying accomplish have camera automatically update when user (my location dot) changes location, only need following:

  1. implement onmylocationchangelistener
  2. mymap.setmylocationenabled(true) (enable my-location layer, has built-in location provider)
  3. mymap.setonmylocationchangelistener(this) (register receive updates when location dot changes location)
  4. in callback method onmylocationchange(location location) update camera accordingly.

you have code of this, see have commented line in step 3, , reason why don't see camera updating.

you don't need implement locationsource , locationlistener (because my-location layer has own location provider), , need onmapclicklistener if want respond user tapping on point on map.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -