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.
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 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
I am using GPS_PROVIDER to get location information ,but it does not work perfectly in some places. Is there any problem when use Gps_Provider. As I know Network_Provider does not give perfect location information. Please help
I have written a small app that receives the location from mobile 3g/wifi by using locationManager & NETWORK_PROVIDER parameter.
according to google's api it will get the location i wish (the other option is using the GPS_PROVIDER)
what i really desired was the WIFI location. I wanted to see its behavior and how the phone gets its location (i.e with wireshark)
in order to do that, i changed into flight mode & activated wifi.
then, i launched the app and clicked the button which starts the NETWORK_PROVIDER location service by calling the requestLocationUpdates function with time parameter = 10.
what that actually happened is that i managed to get the location but saw no traffic at all in wireshark.
could it be that Google gives me the approx. location in advance, when connecting to the wifi? (its the only explenation)
If so, is it possible to clear that cache, or whatever data it have stored, and force the phone to get a new (but the same) location?
Thanks in advance,
Eran.
Have you tried re-booting the phone, just so to remove any cache files which might be storing the location?
Since NETWORK_PROVIDER use cell location, wifi ssid and their signal strength to get your GPS coordinates.
Since you are in flight mode and cannot get cell location, just try to switch the connected wifi , maybe google service will be invoked to get new location.
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.