java - I'm using marker on google map it doesn't update or not moving while i'm walking -


*i'm using marker on google map doesn't update or not moving while i'm walking.. want marker move walk...

*i need use network location while gps location not available need use gps location when it's available...

getandgivelocation.java

 public class getandgivelocation extends service implements locationlistener  {         private final context mcontext;              // flag gps status         boolean isgpsenabled = false;              // flag network status         boolean isnetworkenabled = false;          // flag gps status         boolean cangetlocation = false;          location location; // location         double latitude; // latitude         double longitude; // longitude          // minimum distance change updates in meters         private static final long min_distance_change_for_updates =0; // 10 meters          // minimum time between updates in milliseconds         private static final long min_time_bw_updates = 0; // 2seconds          // declaring location manager         protected locationmanager locationmanager;          public getandgivelocation(context context) {             this.mcontext = context;             getlocation();         }          public location getlocation() {             try {                  locationmanager = (locationmanager) mcontext                         .getsystemservice(location_service);                  criteria criteria = new criteria();                 criteria.setaccuracy(criteria.accuracy_fine);                 criteria.setaltituderequired(false);                 criteria.setbearingrequired(false);                 criteria.setcostallowed(true);                 criteria.setpowerrequirement(criteria.no_requirement);                  string bestprovider = locationmanager.getbestprovider(criteria, true);                  // getting gps status                 isgpsenabled = locationmanager                         .isproviderenabled(locationmanager.gps_provider);                  // getting network status                 isnetworkenabled = locationmanager                         .isproviderenabled(locationmanager.network_provider);                  if (!isgpsenabled && !isnetworkenabled) {                     // no network provider enabled                 } else {                     this.cangetlocation = true;                     // first location network provider                  if (isnetworkenabled) {                          locationmanager.requestlocationupdates(                                 bestprovider,                                 min_time_bw_updates,                                 min_distance_change_for_updates, this);                          log.d("network", "network");                         if (locationmanager != null) {                             location = locationmanager                                     .getlastknownlocation(locationmanager.network_provider);                             if (location != null) {                                 latitude = location.getlatitude();                                 longitude = location.getlongitude();                             }                         }                     }                     // if gps enabled lat/long using gps services                     if (isgpsenabled) {                               locationmanager.requestlocationupdates(                                     bestprovider,                                     min_time_bw_updates,                                     min_distance_change_for_updates, this);                             log.d("gps enabled", "gps enabled");                             if (locationmanager != null) {                                 location = locationmanager.getlastknownlocation(locationmanager.gps_provider);                                 if (location != null) {                                     latitude = location.getlatitude();                                     longitude = location.getlongitude();                                 }                             }                      }                 }              } catch (exception e) {                 e.printstacktrace();             }              return location;         }          /**          * stop using gps listener          * calling function stop using gps in app          * */         public void stopusinggps(){             if(locationmanager != null){                 locationmanager.removeupdates(getandgivelocation.this);             }               }          /**          * function latitude          * */         public double getlatitude(){             if(location != null){                 latitude = location.getlatitude();             }              // return latitude             return latitude;         }          /**          * function longitude          * */         public double getlongitude(){             if(location != null){                 longitude = location.getlongitude();             }              // return longitude             return longitude;         }          /**          * function check gps/wifi enabled          * @return boolean          * */         public boolean cangetlocation() {             return this.cangetlocation;         }          /**          * function show settings alert dialog          * on pressing settings button lauch settings options          * */         public void showsettingsalert(){             alertdialog.builder alertdialog = new alertdialog.builder(mcontext);              // setting dialog title             alertdialog.settitle("gps settings");              // setting dialog message             alertdialog.setmessage("gps not enabled. want go settings menu?");              // on pressing settings button             alertdialog.setpositivebutton("settings", new dialoginterface.onclicklistener() {                 public void onclick(dialoginterface dialog,int which) {                     intent intent = new intent(settings.action_location_source_settings);                     mcontext.startactivity(intent);                 }             });              // on pressing cancel button             alertdialog.setnegativebutton("cancel", new dialoginterface.onclicklistener() {                 public void onclick(dialoginterface dialog, int which) {                 dialog.cancel();                 }             });              // showing alert message             alertdialog.show();         }          @override         public void onlocationchanged(location location) {           }          @override         public void onproviderdisabled(string provider) {         }          @override         public void onproviderenabled(string provider) {         }          @override         public void onstatuschanged(string provider, int status, bundle extras) {         }          @override         public ibinder onbind(intent arg0) {             return null;         }      <code>}</code>      <strong>googlemapviewer.java </strong>      <code>     public class googlemapviewer extends activity {          getandgivelocation currentlocation;         private googlemap googlemap;         double latitude;         double longitude;          @override         protected void oncreate(bundle savedinstancestate) {             // todo auto-generated method stub             super.oncreate(savedinstancestate);              setcontentview(r.layout.googlemap);              try {                  // grabbing location                  retrievelocation();                 // loading map                  initilizemap();              } catch (exception e) {                 e.printstacktrace();             }          }          private void retrievelocation() {              currentlocation = new getandgivelocation(googlemapviewer.this);              if (currentlocation.cangetlocation) {                  latitude = currentlocation.getlatitude();                 longitude = currentlocation.getlongitude();             }          }          private void initilizemap() {             if (googlemap == null) {                 googlemap = ((mapfragment) getfragmentmanager().findfragmentbyid(                         r.id.map)).getmap();                  googlemap.setmaptype(googlemap.map_type_normal);                 // googlemap.setmaptype(googlemap.map_type_satellite);                 // googlemap.setmaptype(googlemap.map_type_hybrid);                 // googlemap.setmaptype(googlemap.map_type_terrain);                  markeroptions marker;                  cameraposition cameraposition = new cameraposition.builder()                         .target(new latlng(latitude, longitude)).tilt(0).zoom(12)                         .build();                  googlemap.animatecamera(cameraupdatefactory                         .newcameraposition(cameraposition));                  googlemap.setmylocationenabled(true);                  marker = new markeroptions()                         .position(new latlng(latitude, longitude))                         .title("title").snippet("just snippet");                  googlemap.addmarker(marker);                  toast.maketext(getbasecontext(),                         "latitude" + latitude + "longitude" + longitude,                         toast.length_long).show();              }         }          @override         protected void onresume() {             super.onresume();             initilizemap();         }      } 


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -