android - Long and lat values are accurate and correct, but blue circle is way off -
i developing location-based android "game" , task @ hand map , running accurate blue circle device's current location. using google api client, google maps api , fused location provider. should mention in china, in case factor. , app runs , without vpn on, keep on.
at first thought long/lat values wrong begin with, hence wrong location on map print them in logcat , google them, found out quite accurate. example screenshot:
i tried on phone, same correct location , same wrong location(!). have tried gps settings, mobile data, wifi, bluetooth, etc. nothing seems improve situation. permissions asked , granted.
however, asked try app bulgaria, , said works accurately on there. confused. ideas causing problem , how fix it? don't think it's problem code in case, there is.
here mapactivity/ oncreate:
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_maps); toolbar mytoolbar = (toolbar) findviewbyid(r.id.map_toolbar); setsupportactionbar(mytoolbar); mytoolbar.settitle("map"); mgoogleapiclient = new googleapiclient.builder(this) //.enableautomanage(this, this) .addapi(locationservices.api) .addconnectioncallbacks(this) .addonconnectionfailedlistener(this) .build(); supportmapfragment mapfragment = (supportmapfragment) getsupportfragmentmanager() .findfragmentbyid(r.id.map); mapfragment.getmapasync(this); }
mapactivity/ onconnected:
@override public void onconnected(bundle bundle) { // last known recent location. if (contextcompat.checkselfpermission(this.getapplicationcontext(), android.manifest.permission.access_fine_location) == packagemanager.permission_granted) { mlocationpermissiongranted = true; } else { activitycompat.requestpermissions(this, new string[]{android.manifest.permission.access_fine_location}, permissions_request_access_fine_location); } if (mlocationpermissiongranted) { location mcurrentlocation = locationservices.fusedlocationapi.getlastlocation(mgoogleapiclient); // note can null if last location isn't known. if (mcurrentlocation != null) { // print current location if not null log.d("debug", "current location: " + mcurrentlocation.tostring()); latlng latlng = new latlng(mcurrentlocation.getlatitude(), mcurrentlocation.getlongitude()); mlastknownlocation = mcurrentlocation; mmap.setmylocationenabled(true); mmap.getuisettings().setmaptoolbarenabled(true); cameraupdate = cameraupdatefactory.newlatlngzoom(latlng, 17); mmap.animatecamera(cameraupdate); } } // begin polling new location updates. startlocationupdates(); }
mapactivity/ startlocationupdates:
protected void startlocationupdates() { // create location request locationrequest = locationrequest.create() .setpriority(locationrequest.priority_high_accuracy) .setinterval(update_interval) .setfastestinterval(fastest_interval); // request location updates if (contextcompat.checkselfpermission(this.getapplicationcontext(), android.manifest.permission.access_fine_location) == packagemanager.permission_granted) { mlocationpermissiongranted = true; } else { activitycompat.requestpermissions(this, new string[]{android.manifest.permission.access_fine_location}, permissions_request_access_fine_location); } if (mlocationpermissiongranted) { locationservices.fusedlocationapi.requestlocationupdates(mgoogleapiclient, locationrequest, new locationlistener() { @override public void onlocationchanged(location location) { string msg = "updated location: " + double.tostring(location.getlatitude()) + "," + double.tostring(location.getlongitude()); log.d("this", msg); //toast.maketext(this, msg, toast.length_short).show(); // can create latlng object use maps latlng latlng = new latlng(location.getlatitude(), location.getlongitude()); mlastknownlocation = location; cameraupdate = cameraupdatefactory.newlatlngzoom(latlng, 17); mmap.animatecamera(cameraupdate); } }); } mmap.setmylocationenabled(true); mmap.getuisettings().setmaptoolbarenabled(true); }
mapactivity/ createlocationrequest:
protected locationrequest createlocationrequest() { locationrequest mlocationrequest = new locationrequest(); mlocationrequest.setinterval(10000); mlocationrequest.setfastestinterval(5000); mlocationrequest.setpriority(locationrequest.priority_high_accuracy); return mlocationrequest; }
and onmapready:
@override public void onmapready(googlemap googlemap) { mmap = googlemap; // toolbar covering on location button, // adding padding gets out of way mmap.setpadding(0, 200, 0, 0); }
Comments
Post a Comment