I want to get current location (latitude & longitude) , when WiFi & Gps is off .It is possible to get latitude and longitude from mobile sim network. I searched more on google but i did not get satisfies answers.
Try This
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if(location==null){
location = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
}
From my yesterday's experience on this question, I finally found out that it is impossible to fetch latitude longitude's value without Internet connection in device. ( Gosh I spent 3 hours to find why my running code working properly. ) Even to get the value from getLastKnowLocation() you must require Internet connection.
Pretty sure this is impossible. While you can store cell tower ID's to know when you're close to an area you've been in before, you can't actually use these values to get latitude and longitude numbers (Well, unless you stored some lat and long values and paired them with that cell tower). You can however call getLastKnownLocation() to... get the last known location from the GPS or Wifi.
Edit
Apparently google has built a database of lat/long with cellID's already. It is not part of the standard Android API, and requires a network connection to hit. Pretty cool though. You can find more at this (really slow) website
Related
I am currently able to get the city name in an Android application using GPS or network provider.
I tried with LocationManager, but if GPS is off the location manager and location is null. To improve the battery performance I don't want to turn on the GPS.
Is there any way without turning on the GPS able to get the city name in an Android application? Or if GPS is off why is location manager returning null? How can I solve this?
Querying the following URL will give the current IP address and location in JSON:
http://ip-api.com/json
You can then parse that to extract the values you want.
I am developing an android application in which i want to use wifi only to find user's location is it possible to find location of your device just by using Wifi ?
In this app i m trying to guide user to go from one place to another inside a building so i want exact location cell tower location or gps location will not be of any help
LocationManager.NETWORK_PROVIDER will use either Wifi or cell tower location (not GPS). If you want the best location, that would be fine GPS (wifi is the least accurate.) You can ask the LocationManager to getBestProvider and require fine GPS with:
criteria.setAccuracy(Criteria.ACCURACY_FINE);
Based on your latest comment, I think you would like to guide a user inside a building and somehow get more accurate locations than a gps location (which would probably not be accurate inside a building anyway). While there may be some specific situation in which this would be possible, I would say no, there is not a general solution that could be applied.
For Current Location, using GPS is highly recommended. Because with only Wifi, it will not be accurate. But still you can use this:
String uriName = "geo:"+ lat+ "," + lon+ "?q=my+street+address";
startActivity(new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uriName)));
This should work with roughly accuracy.
I think you want to guide the user while inside the building, if so, then I don't think that GPS or Wifi will be able to help you.
GPS provides a very fine location but require clear contact with the gps satellites in the space which won't be available inside buildings. Also the accuracy is within some meter distance which won't be effective in your case.
Cellular wifi will provide you location using the nearby cell tower which i think is self explanatory in your case. So, I don't think that both location services will of use in your case.
I am using this code to get the location provider and location.
mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
mBestProvider = mLocationManager.getBestProvider(criteria, false);
mLocation = mLocationManager.getLastKnownLocation(mBestProvider);
If I turn off the GPS, the location is by network, but if I reboot the phone(so I loss the last position known) and with the 3G data connections off. So I am only using WIFI, I cant get any provider thus therefore any location. However google places app can locate me. I think it might be getting the lastknownlocation.But in that case my others applications should be able to get that location. Any idea whats happening?
The way you are calling this it will return all providers enabled or not because you are passing it false which is probably your intention but have you checked the return string?
mBestProvider = mLocationManager.getBestProvider(criteria, false);
You might be getting the gps provider, or you might be getting the network provider, I have learned not to trust the criteria mechanism because it seems to work differently per carrier and device (I have had some weird bugs reported because of this)
So I always ask specifically for gps and network providers and check last known for both, then use an algo to determine the best one to use.
The network provider can use cell or wifi hotspot/routers to determine location (google keeps a database of wifi information) so it's possible to get a fix with just wifi, not saying that is whats happening but it could be.
If that bears no fruit then it's possible that they are simply caching the last location update in preferences, some applications do that. To test the thesis, failing all of the above just leave the phone in that state and move to a very different location with the same properties if possible, should only take 2000 meters or so. If your app still reports null and places reports the old location you have your answer.
If places did report the newer location with wifi, and your app cannot (assuming you actually verify you are getting the network provider) then there is a chance they are using a private API via the Google Location Server (GLS) / MASF server via partial cell / wifi info but that's at the extreme end of the tin foil curve.
I am developing a android application in that i want find the user location using GPS. That is working fine .But if the GPS is Disabled means i want to find the user location based on the CellID and Loc .It is possible or not
It is possible means please tell me how to do that with sample code
Waiting for reply
Just request the "best" location provider, and you'll either get the GPS if it's available or the network (wifi / cell) if it's not.
LocationManager.getBestProvider()
You don't need to explicitly code to either GPS / network providers.
Here is complete tutorial of Location-Based Services Using CellID in Android.
i did the GPS application which gets the current location.It is working in android emulator by using DDMS perspective(by passing mock location).But it is not working in android phone and phone is Samsung gt-i5801.please help me.
And one more thing i want to ask you guys.
(Why i need Gps) bcoz
in my appln i want to display the nearest cinema theatres by using latitude and longitude.
Is there any other way to do that.
Please tell me.
I think there is no problem in your code if it runs in emulator. But you have not start the gps on your phone, so it's giving a null pointer exception.
So now when you use gps, first check whether gps is on or not. Then fetch lat. and long.
You can check your gps is on or off by this:
LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
boolean val= mlocManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
First of all, tell us what errors are you getting when you run it on the device. Logcat messages!?
Secondly, there must be any webservice which gives you the nearby cinema theatres, so you might be required to give it your current location in latitude and longitude.
For getting your current location, GPS is necessary.
On the other note, you can also use NETWORK_PROVIDER to get your current location.