but the requestLocationUpdates can be passed with any one provider I guess and the Service will take one think particularly and will poll location based on that instant only !!!
On Fri, Oct 4, 2013 at 7:43 PM, Mukesh Srivastav <[email protected]>wrote: > Look, you are only checking for the best location but, I would suggest to > check all the possibilities. > > Please try the below code > public Location getLocation() { > try { > locationManager = (LocationManager) this > .getSystemService(LOCATION_SERVICE); > > // getting GPS status > isGPSEnabled = locationManager > .isProviderEnabled(LocationManager.GPS_PROVIDER); > > // getting network status > isNetworkEnabled = locationManager > .isProviderEnabled(LocationManager.NETWORK_PROVIDER); > > if (!isGPSEnabled && !isNetworkEnabled) { > // no network provider is enabled > } else { > LocationListener mlocListener = new GPSListener(parentcontext); > this.canGetLocation = true; > if (isNetworkEnabled) { > locationManager.requestLocationUpdates( > LocationManager.NETWORK_PROVIDER, > MIN_TIME_BW_UPDATES, > MIN_DISTANCE_CHANGE_FOR_UPDATES, mlocListener); > Log.d("Network", "Network Enabled"); > if (locationManager != null) { > location = locationManager > .getLastKnownLocation(LocationManager.NETWORK_PROVIDER); > if (location != null) { > latitude = location.getLatitude(); > longitude = location.getLongitude(); > PalsApplication.glatitude = latitude; > PalsApplication.glongitude = longitude; > } > } > } > // if GPS Enabled get lat/long using GPS Services > if (isGPSEnabled) { > if (location == null) { > locationManager.requestLocationUpdates( > LocationManager.GPS_PROVIDER, > MIN_TIME_BW_UPDATES, > MIN_DISTANCE_CHANGE_FOR_UPDATES, mlocListener); > Log.d("GPS", "GPS Enabled"); > if (locationManager != null) { > location = locationManager > .getLastKnownLocation(LocationManager.GPS_PROVIDER); > if (location != null) { > latitude = location.getLatitude(); > longitude = location.getLongitude(); > PalsApplication.glatitude = latitude; > PalsApplication.glongitude = longitude; > } > } > } > } > } > > } catch (Exception e) { > e.printStackTrace(); > } > > return location; > } > > > > On Fri, Oct 4, 2013 at 7:28 PM, HImanshu Mittal <[email protected]>wrote: > >> But when I open my map >> And as i have done >> maps.setmylocationenabled >> than the blue dot comes at the position where I am >> But the same doesn't come when I use it in my service >> Thats y I was asking how to fix it !!! >> >> >> On Fri, Oct 4, 2013 at 7:06 PM, Kristopher Micinski < >> [email protected]> wrote: >> >>> I guess the problem is, if your location is unavailable, how are you >>> expecting that that will be fixed? This doesn't make any sense, if it's >>> not available, it's not available, >>> >>> Kris >>> >>> >>> >>> On Fri, Oct 4, 2013 at 6:16 AM, HImanshu Mittal >>> <[email protected]>wrote: >>> >>>> Hello friends, >>>> I have just checked it out that my service is working fine but the >>>> problem is I am in an area where location is unavalaible and my friend is >>>> in an area where location is availaible. >>>> How should* *I fix this that my location also can be transmitted to my >>>> server!!! >>>> >>>> Now I think ii could be solved >>>> Please Help!! >>>> >>>> >>>> On Fri, Oct 4, 2013 at 9:47 AM, HImanshu Mittal <[email protected] >>>> > wrote: >>>> >>>>> package com.example.metro; >>>>> >>>>> import com.dude5692.StaticURL.ProjectURL; >>>>> >>>>> import json.jSOn; >>>>> >>>>> import android.app.Service; >>>>> import android.content.Context; >>>>> import android.content.Intent; >>>>> import android.content.SharedPreferences; >>>>> import android.location.Criteria; >>>>> import android.location.Location; >>>>> import android.location.LocationListener; >>>>> import android.location.LocationManager; >>>>> import android.os.AsyncTask; >>>>> import android.os.Bundle; >>>>> import android.os.IBinder; >>>>> import android.widget.Toast; >>>>> >>>>> public class MyService extends Service >>>>> { >>>>> ProjectURL proURL = new ProjectURL(); >>>>> String initialURL; >>>>> SharedPreferences pref; >>>>> >>>>> @Override >>>>> public void onCreate() >>>>> { >>>>> // TODO Auto-generated method stub >>>>> super.onCreate(); >>>>> final LocationManager mlocmag = >>>>> (LocationManager)getSystemService(Context.LOCATION_SERVICE); >>>>> final LocationListener mlocList = new MyLocationList(); >>>>> >>>>> Criteria criteria = new Criteria(); >>>>> >>>>> // Getting the name of the best provider >>>>> final String provider = mlocmag.getBestProvider(criteria, true); >>>>> >>>>> final Location loc = mlocmag.getLastKnownLocation(provider); >>>>> UpdateWithNewLocation(loc); // This method is used to get updated >>>>> location. >>>>> mlocmag.requestLocationUpdates(provider, 1000, 0, mlocList); >>>>> } >>>>> >>>>> @Override >>>>> public IBinder onBind(Intent arg0) >>>>> { >>>>> // TODO Auto-generated method stub >>>>> return null; >>>>> } >>>>> >>>>> @Override >>>>> public void onDestroy() >>>>> { >>>>> // TODO Auto-generated method stub >>>>> super.onDestroy(); >>>>> } >>>>> >>>>> @Override >>>>> public int onStartCommand(Intent intent, int flags, int startId) >>>>> { >>>>> // TODO Auto-generated method stub >>>>> return super.onStartCommand(intent, flags, startId); >>>>> } >>>>> private void UpdateWithNewLocation(final Location loc) >>>>> { >>>>> // TODO Auto-generated method stub >>>>> if(loc!= null) >>>>> { >>>>> final double lat =loc.getLatitude(); // Updated lat >>>>> final double Long = loc.getLongitude(); // Updated long >>>>> >>>>> pref = getSharedPreferences("myMetroFile",Context.MODE_PRIVATE); >>>>> System.out.println("MO Service Running"); >>>>> String UniqueDeviceId = pref.getString("DeviceUniqueID", "0"); >>>>> initialURL = proURL.projectURL + >>>>> "storeLatLong.php?RegID="+lat+"&Email="+Long+"&Device="+UniqueDeviceId+"&Start=NO"; >>>>> new Async().execute(); >>>>> } >>>>> else >>>>> { >>>>> } >>>>> } >>>>> >>>>> class Async extends AsyncTask<String, Void, String> >>>>> { >>>>> >>>>> //ProgressDialog progress; >>>>> >>>>> protected String doInBackground(String... params) >>>>> { >>>>> try >>>>> { >>>>> new jSOn().execute(initialURL); >>>>> } >>>>> catch (Exception e) >>>>> { >>>>> e.printStackTrace(); >>>>> } >>>>> return null; >>>>> } >>>>> >>>>> protected void onPreExecute() >>>>> { >>>>> super.onPreExecute(); >>>>> } >>>>> >>>>> protected void onPostExecute(String result) >>>>> { >>>>> super.onPostExecute(result); >>>>> } >>>>> } >>>>> >>>>> public class MyLocationList implements LocationListener >>>>> { >>>>> >>>>> public void onLocationChanged(Location arg0) >>>>> { >>>>> // TODO Auto-generated method stub >>>>> UpdateWithNewLocation(arg0); >>>>> } >>>>> >>>>> public void onProviderDisabled(String provider) >>>>> { >>>>> // TODO Auto-generated method stub >>>>> Toast.makeText(getApplicationContext(),"GPS Disable ", >>>>> Toast.LENGTH_LONG).show(); >>>>> } >>>>> >>>>> public void onProviderEnabled(String provider) >>>>> { >>>>> // TODO Auto-generated method stub >>>>> Toast.makeText(getApplicationContext(),"GPS enabled", >>>>> Toast.LENGTH_LONG).show(); >>>>> } >>>>> >>>>> public void onStatusChanged(String provider, int status, Bundle >>>>> extras) >>>>> { >>>>> // TODO Auto-generated method stub >>>>> } >>>>> } >>>>> } >>>>> >>>>> >>>>> On Fri, Oct 4, 2013 at 4:44 AM, Lew <[email protected]> wrote: >>>>> >>>>>> HImanshu Mittal wrote: >>>>>> >>>>>>> Bro , Don't dramatize things out here. I have asked a question thats >>>>>>> it. >>>>>>> >>>>>> >>>>>> How is asking for relevant details dramatizing it? >>>>>> >>>>>> It's spelled "that's". >>>>>> >>>>>> >>>>>>> For the first the first time I have asked a question on any forum >>>>>>> regarding a help in my 8 months of development time. >>>>>>> >>>>>> >>>>>> Not important. >>>>>> >>>>>> >>>>>>> I was not able to make a code because the code which I have made is >>>>>>> not working. >>>>>>> >>>>>> >>>>>> That's like telling a doctor, "I don't feel well" and expecting a >>>>>> diagnosis. You need to provide details. >>>>>> >>>>>> >>>>>>> If you can provide the code than it will be really be helpful or I >>>>>>> can also post my code out here than you can tell me where I am doing it >>>>>>> wrong >>>>>>> >>>>>> >>>>>> >>>>>>> :) >>>>>>> >>>>>>> >>>>>> Since that's what the guy was asking for, why do you give him a hard >>>>>> time? >>>>>> >>>>>>> >>>>>>> On Thu, Oct 3, 2013 at 9:23 PM, Steve Gabrilowitz < >>>>>>> [email protected]> wrote: >>>>>>> >>>>>>>> You are more likely to get help developing your own service if tell >>>>>>>> us in which areas you have been less than successful. If you are >>>>>>>> looking >>>>>>>> for a full piece of code already written for you then try Google ;-) >>>>>>>> >>>>>>> Follow his advice. >>>>>> >>>>>> -- >>>>>> Lew >>>>>> >>>>>> >>>>>> -- >>>>>> You received this message because you are subscribed to the Google >>>>>> Groups "Android Developers" group. >>>>>> To post to this group, send email to >>>>>> [email protected] >>>>>> To unsubscribe from this group, send email to >>>>>> [email protected] >>>>>> For more options, visit this group at >>>>>> http://groups.google.com/group/android-developers?hl=en >>>>>> --- >>>>>> You received this message because you are subscribed to a topic in >>>>>> the Google Groups "Android Developers" group. >>>>>> To unsubscribe from this topic, visit >>>>>> https://groups.google.com/d/topic/android-developers/cFXbDUmDh6E/unsubscribe >>>>>> . >>>>>> To unsubscribe from this group and all its topics, send an email to >>>>>> [email protected]. >>>>>> For more options, visit https://groups.google.com/groups/opt_out. >>>>>> >>>>> >>>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Android Developers" group. >>>> To post to this group, send email to >>>> [email protected] >>>> To unsubscribe from this group, send email to >>>> [email protected] >>>> For more options, visit this group at >>>> http://groups.google.com/group/android-developers?hl=en >>>> --- >>>> You received this message because you are subscribed to the Google >>>> Groups "Android Developers" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to [email protected]. >>>> >>>> For more options, visit https://groups.google.com/groups/opt_out. >>>> >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Android Developers" group. >>> To post to this group, send email to [email protected] >>> To unsubscribe from this group, send email to >>> [email protected] >>> For more options, visit this group at >>> http://groups.google.com/group/android-developers?hl=en >>> --- >>> You received this message because you are subscribed to a topic in the >>> Google Groups "Android Developers" group. >>> To unsubscribe from this topic, visit >>> https://groups.google.com/d/topic/android-developers/cFXbDUmDh6E/unsubscribe >>> . >>> To unsubscribe from this group and all its topics, send an email to >>> [email protected]. >>> For more options, visit https://groups.google.com/groups/opt_out. >>> >> >> -- >> You received this message because you are subscribed to the Google >> Groups "Android Developers" group. >> To post to this group, send email to [email protected] >> To unsubscribe from this group, send email to >> [email protected] >> For more options, visit this group at >> http://groups.google.com/group/android-developers?hl=en >> --- >> You received this message because you are subscribed to the Google Groups >> "Android Developers" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> For more options, visit https://groups.google.com/groups/opt_out. >> > > > > -- > Warm Regards, > *Mukesh Kumar*, > Android Consultant/Freelancer, > India,Hyderabad. > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > --- > You received this message because you are subscribed to a topic in the > Google Groups "Android Developers" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/android-developers/cFXbDUmDh6E/unsubscribe > . > To unsubscribe from this group and all its topics, send an email to > [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.

