Reputation: 638
I'm trying to implement a location tracker sort of application. I need to get location at specific times, but while I trying I notice that, if my phone doesn't get gps location it doesn't look for network location. When I turn of gps at my phone's settings It gets network location. How can I use both or set what to use at code. I use java ME location API. Thanks in advance.
Edit: here is my code for getting location:
Criteria cr= new Criteria();
cr.setHorizontalAccuracy(500);
cr.setCostAllowed(true);
// Get an instance of the provider
LocationProvider lp= LocationProvider.getInstance(cr);
// Request the location, setting a one-minute timeout
Location l = lp.getLocation(60);
QualifiedCoordinates c = l.getQualifiedCoordinates();
if(c != null ) {
// Use coordinate information
double lat = c.getLatitude();
double lon = c.getLongitude();
double acc = c.getHorizontalAccuracy();
form.append("latitude: " + lat);
form.append("\nlongitude: " + lon);
form.append("\nacc: " + acc);
}
Upvotes: 0
Views: 1589
Reputation: 16
You can not define the method for the location provider with the API. Implementation is transparent for the hardware (which is behind this operation). What you have wrote is correct. You can get a location only from one source and this source depends on phone settings (location settings).
However you can try to read the network based location by identifying the network's cell associated with the device. This article provided with a code sample should be usefull.
Upvotes: 0