Why I cant search location in below lollipop version? - android

i have a problem while loading map in lollipop version i cant get location while i search in map. it showing no location found, but it works in above marsmallow version.i dont know what mistake i have done.pls anyone give a solution to find out.
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, true);
// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(provider, 1000, 1, locationListener);
currentLocation = locationManager.getLastKnownLocation(provider);
//currentLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (currentLocation != null) {
current = new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude());
//get location details
Geocoder gcd = new Geocoder(this, Locale.getDefault());
List<Address> addresses = null;
try {
addresses = gcd.getFromLocation(current.latitude, current.longitude, 1);
Log.e(TAG, "addresses: "+addresses );
} catch (IOException e) {
e.printStackTrace();
}
if (addresses != null && addresses.size() > 0) {
addr = addresses.get(0).getAddressLine(0);
}
CurrMarker = googleMap.addMarker(new MarkerOptions().position(current).title("Current Position").snippet(addr));
addCameraToMap(current);
} else {
Toast.makeText(this, "UnAvailable", Toast.LENGTH_SHORT).show();
}

Add following permission in AndroidManifest file
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

First Add Permission to your Manifest file:
After Permission added to your Manifest:
int permissionPhoneState = ContextCompat.checkSelfPermission("Your Activity Name",
Manifest.permission.ACCESS_FINE_LOCATION);
int permissionPhoneState1 = ContextCompat.checkSelfPermission("Your Activity Name", Manifest.permission.ACCESS_COARSE_LOCATION);
if ((permissionPhoneState == PackageManager.PERMISSION_GRANTED) && (permissionPhoneState1 == PackageManager.PERMISSION_GRANTED)) {
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
location(location);
} else {
ActivityCompat.requestPermissions("Your Activity Name", new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, 2);
}
private void location(Location location) {
if (location != null) {
location.setLatitude(location.getLatitude());
location.setLongitude(location.getLongitude());
final MarkerOptions markerOptions = new MarkerOptions();
final LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
markerOptions.position(latLng);
}
}
Hope this one help you

locationManager.requestLocationUpdates() is an Asynchronous call you are using currentLocation = locationManager.getLastKnownLocation(provider); which might not have received your current location yet as async call might not have been completed. Make sure you are using onLocationChanged() callback to get your location.

Related

How to get gps latitude and longitude of a device?

Someone please suggest a code to get gps location(latitude and longitude) of a android device in android. I tried so many examples but in
Location location = locationManager.getLastKnownLocation(bestProvider);
getting location=null.
I am posting my code below.
public class MainActivity extends AppCompatActivity {
Geocoder geocoder;
String bestProvider;
List<Address> user = null;
double lat,lng;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LocationManager lm = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
bestProvider = lm.getBestProvider(criteria, false);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
Location location = lm.getLastKnownLocation(bestProvider);
if (location == null)
{
Toast.makeText(this,"Location Not found",Toast.LENGTH_LONG).show();
}
else{
geocoder = new Geocoder(this);
try
{
user = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
lat=(double)user.get(0).getLatitude();
lng=(double)user.get(0).getLongitude();
System.out.println(" DDD lat: " +lat+", longitude: "+lng);
}catch (Exception e) {
e.printStackTrace();
}
}
}
}
you can try with the LocationManager.
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
double longitude = location.getLongitude();
double latitude = location.getLatitude();
then you LocationListener which will give you asynchronous updates of your location.
private final LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
longitude = location.getLongitude();
latitude = location.getLatitude();
}
}
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 10, locationListener);
also add permissions into your manifest file:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.location.gps" />
<uses-permission android:name="android.permission.INTERNET" />
I hope this will help you.

Getting LocationManager and Longitude-Latitude null in Some devices like Google Pixel,Moto G4,OnePlus 6

I try to get my current location with below code but it is return
longitude and latitude null or 0,0 in above mention device(Pixel os
8.0,Moto os 7.0,OnePlus 8.0).In other device with same os it is working fine.This is my code.
if (isNetworkEnabled) {
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
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 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, 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();
}
if (location == null || location.getAccuracy() < location.getAccuracy()) {
// Found best last known location: %s", l);
location = location;
}
}
}
}
Get Last Known Location Method
private Location getLastKnownLocation() {
locationManager = (LocationManager)mContext.getSystemService(LOCATION_SERVICE);
List<String> providers = locationManager.getProviders(true);
Location bestLocation = null;
for (String provider : providers) {
Location l = locationManager.getLastKnownLocation(provider);
if (l == null) {
continue;
}
if (bestLocation == null || l.getAccuracy() < bestLocation.getAccuracy()) {
// Found best last known location: %s", l);
bestLocation = l;
}
}
return bestLocation;
}
onLocationChanged(Location location) method
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
String add=addresses.get(0).getAddressLine(1)+", "+addresses.get(0).getAddressLine(2);
Try with the Fused Location API , which is a higher-level Google Play Services API that wraps the underlying location sensors like GPS.
Usage:
Add dependency in app/build.gradle
dependencies {
api 'com.google.android.gms:play-services-location:11.8.0'
}
Permissions required:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Connecting to the LocationServices API
private LocationRequest mLocationRequest;
private long UPDATE_INTERVAL = 10 * 1000; /* 10 secs */
private long FASTEST_INTERVAL = 2000; /* 2 sec */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
startLocationUpdates();
}
// Trigger new location updates at interval
protected void startLocationUpdates() {
// Create the location request to start receiving updates
mLocationRequest = new LocationRequest();
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
mLocationRequest.setInterval(UPDATE_INTERVAL);
mLocationRequest.setFastestInterval(FASTEST_INTERVAL);
// Create LocationSettingsRequest object using location request
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
builder.addLocationRequest(mLocationRequest);
LocationSettingsRequest locationSettingsRequest = builder.build();
// Check whether location settings are satisfied
// https://developers.google.com/android/reference/com/google/android/gms/location/SettingsClient
SettingsClient settingsClient = LocationServices.getSettingsClient(this);
settingsClient.checkLocationSettings(locationSettingsRequest);
// new Google API SDK v11 uses getFusedLocationProviderClient(this)
getFusedLocationProviderClient(this).requestLocationUpdates(mLocationRequest, new LocationCallback() {
#Override
public void onLocationResult(LocationResult locationResult) {
// do work here
onLocationChanged(locationResult.getLastLocation());
}
},
Looper.myLooper());
}
and then register for location updates with onLocationChanged
public void onLocationChanged(Location location) {
// New location has now been determined
String msg = "Updated Location: " +
Double.toString(location.getLatitude()) + "," +
Double.toString(location.getLongitude());
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
// You can now create a LatLng Object for use with maps
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
}
For more info go through guides.codepath.com guide

How to get current latitude and longitude without using google maps android

I am trying to get the current location of the user either by GPS or location provider but every solution I have tried (many from stacksoverflow and google, youtube as well) gives a null as latitude and longitude.
Here is the code I am using
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
criteria.setAltitudeRequired(false);
criteria.setSpeedRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(false);
double lat = 0;
double lng = 0;
provider = locationManager.getBestProvider(criteria, false);
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
Location location = locationManager.getLastKnownLocation(provider);
if (location != null)
{
lat = location.getLatitude();
lng = location.getLongitude();
Toast.makeText(this,"Location"+lat+" "+lng+" ",Toast.LENGTH_LONG).show();
}else
Toast.makeText(this,"Location"+lat+" "+lng+" ",Toast.LENGTH_LONG).show();
The above code always gives 0.0 and 0.0 as lat and long.
I have also included the permissions in Android Manifest :
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
Any suggestions please?
This is all I used for my project. Hope it helps!
Declarations:
Location location;
LocationManager locationManager;
String provider;
onCreate:
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
provider = locationManager.getBestProvider(new Criteria(), false);
locationManager.requestLocationUpdates(provider, 400, 1, this);
location = locationManager.getLastKnownLocation(provider);
lat = location.getLatitude(); long = location.getLongitude();
public static void getLocation(final Context context, final Looper looper, final LocationUpdateListener locationUpdateListener, final LocationListener locationListener) {
try {
boolean isProviderEnabled;
Location location;
final LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
isProviderEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
if (isProviderEnabled) {
if (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
locationManager.requestSingleUpdate(LocationManager.GPS_PROVIDER, locationListener, looper);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
locationManager.removeUpdates(locationListener);
}
getBackupLocation(context, looper, locationUpdateListener, locationListener);
}
}, 10000);
return;
}
}
isProviderEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (isProviderEnabled) {
locationManager.requestSingleUpdate(LocationManager.NETWORK_PROVIDER, locationListener, looper);
return;
}
location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null) {
if (locationUpdateListener != null) {
locationUpdateListener.onLocationUpdate(location);
locationManager.removeUpdates(locationListener);
}
return;
}
location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
if (locationUpdateListener != null) {
locationUpdateListener.onLocationUpdate(location);
locationManager.removeUpdates(locationListener);
}
return;
}
float defaultValue = -10000;
SharedManager sharedManager = SharedManager.getInstance();
double lat = sharedManager.getDoubleValue(SharedManager.LAT, defaultValue);
double lng = sharedManager.getDoubleValue(SharedManager.LNG, defaultValue);
if (lat != defaultValue && lng != defaultValue) {
location = new Location(LocationManager.PASSIVE_PROVIDER);
location.setLatitude(lat);
location.setLongitude(lng);
if (locationUpdateListener != null) {
locationUpdateListener.onLocationUpdate(location);
locationManager.removeUpdates(locationListener);
}
return;
}
location = new Location(LocationManager.PASSIVE_PROVIDER);
location.setLatitude(PASSIVE_LAT);
location.setLongitude(PASSIVE_LONG);
if (locationUpdateListener != null) {
locationUpdateListener.onLocationUpdate(location);
locationManager.removeUpdates(locationListener);
}
}
catch(
Exception e)
{
//No Location
Location location = new Location(LocationManager.PASSIVE_PROVIDER);
location.setLatitude(PASSIVE_LAT);
location.setLongitude(PASSIVE_LONG);
if (locationUpdateListener != null) {
locationUpdateListener.onLocationUpdate(location);
}
}
}
Working function that checks GPS , Network and LastKnownLocation..
my Suggestion : First use LastKnownLocation then Netowrk and last Resort as GPS.. less Battery usage.
Location results return to the Listeners.

Marker not displaying on GoogleMap

I am trying to add multiple markers on GoogleMap. This is what I am doing:
private void initilizeMap() {
try {
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager()
.findFragmentById(R.id.map)).getMap();
// Enabling MyLocation Layer of Google Map
googleMap.setMyLocationEnabled(true);
if (googleMap != null)
addMarkers();
// Getting LocationManager object from System Service
// LOCATION_SERVICE
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
// Creating a criteria object to retrieve provider
Criteria criteria = new Criteria();
// Getting the name of the best provider
String provider = locationManager.getBestProvider(criteria,
true);
// Getting Current Location
Location location = locationManager
.getLastKnownLocation(provider);
if (location != null) {
onLocationChanged(location);
}
locationManager
.requestLocationUpdates(provider, 20000, 0, this);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
Following function adds markers:
private void addMarkers() {
try {
for (String title : locations.keySet()) {
if (locations.get(title).getLatitude() != 0
&& locations.get(title).getLongitude() != 0) {
// create marker
MarkerOptions marker = new MarkerOptions().position(
new LatLng(locations.get(title).getLatitude(),
locations.get(title).getLongitude()))
.title(title);
marker.icon(BitmapDescriptorFactory
.fromResource(R.drawable.pin_map));
// adding marker
googleMap.addMarker(marker);
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
But markers are not displaying, though they are adding up on GoogleMap which I checked while debugging. No exception coming as well. I tried to change the icon image, still not working.
You are most probably using the old int values for latitude/longitude as they where expected for the GeoPoint of the previous GoogleMaps API. These are 1 million times too big for the new LatLng object, which expects double values rather than integers.

My current location always returns null. How can I fix this?

I am trying to find my current location for an android project. When the application is loaded my current location is always null. I have set up the permissions in the manifest etc. When I find the current location I intend to use the coordinates to find distances to other locations on the map. My code snippet is below. Why do I always get a null value?
locMan = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria crit = new Criteria();
towers = locMan.getBestProvider(crit, false);
location = locMan.getLastKnownLocation(towers);
if (location != null) {
System.out.println("Location is not null!");
lat = (int) (location.getLatitude() *1E6);
longi = (int) (location.getLongitude() * 1E6);
GeoPoint ourLocation = new GeoPoint(lati, longi);
OverlayItem overlayItem = new OverlayItem(ourLocation, "1st String",
"2nd String");
CustomPinpoint custom = new CustomPinpoint(d, MainMap.this);
custom.insertPinpoint(overlayItem);
overlayList.add(custom);
overlayList.clear();
} else {
System.out.println("Location is null! " + towers);
Toast.makeText(MainMap.this, "Couldn't get provider",Toast.LENGTH_SHORT)
.show();
}
getLastKnownLocation() uses the location(s) previously found by other applications. if no application has done this, then getLastKnownLocation() will return null.
One thing you can do to your code to have a better chance at getting as last known location- iterate over all of the enabled providers, not just the best provider. For example,
private Location getLastKnownLocation() {
List<String> providers = mLocationManager.getProviders(true);
Location bestLocation = null;
for (String provider : providers) {
Location l = mLocationManager.getLastKnownLocation(provider);
ALog.d("last known location, provider: %s, location: %s", provider,
l);
if (l == null) {
continue;
}
if (bestLocation == null
|| l.getAccuracy() < bestLocation.getAccuracy()) {
ALog.d("found best last known location: %s", l);
bestLocation = l;
}
}
if (bestLocation == null) {
return null;
}
return bestLocation;
}
If your app can't deal without having a location, and if there's no last known location, you will need to listen for location updates. You can take a look at this class for an example,
https://github.com/farble1670/autobright/blob/master/src/org/jtb/autobright/EventService.java
See the method onStartCommand(), where it checks if the network provider is enabled. If not, it uses last known location. If it is enabled, it registers to receive location updates.
if u find current location of devices the use following method in main class
public void find_Location(Context con) {
Log.d("Find Location", "in find_location");
this.con = con;
String location_context = Context.LOCATION_SERVICE;
locationManager = (LocationManager) con.getSystemService(location_context);
List<String> providers = locationManager.getProviders(true);
for (String provider : providers) {
locationManager.requestLocationUpdates(provider, 1000, 0,
new LocationListener() {
public void onLocationChanged(Location location) {}
public void onProviderDisabled(String provider) {}
public void onProviderEnabled(String provider) {}
public void onStatusChanged(String provider, int status,
Bundle extras) {}
});
Location location = locationManager.getLastKnownLocation(provider);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
addr = ConvertPointToLocation(latitude, longitude);
String temp_c = SendToUrl(addr);
}
}
}
And Add User Permission method in your manifest file
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
Try this this will not give you null current location
class GetLastLocation extends TimerTask {
LocationManager mlocManager = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
LocationListener mlocListenerTmp = new CustomLocationListener();
private final Handler mLocHandler;
public GetLastLocation(Handler mLocHandler) {
this.mLocHandler = mLocHandler;
}
#Override
public void run() {
timer.cancel();
mlocManager.removeUpdates(mlocListenerTmp);
Location location = mlocManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
{
if (mlocListenerTmp != null) {
mlocManager.removeUpdates(mlocListenerTmp);
}
currentLocation = location;
}
if (location != null) {
String message = String.format(
"Location \n Longitude: %1$s \n Latitude: %2$s",
location.getLongitude(), location.getLatitude());
Log.d("loc", " :" + message);
Bundle b = new Bundle();
{
b.putBoolean("locationRetrieved", true);
{
Message msg = Message.obtain();
{
msg.setData(b);
mLocHandler.sendMessage(msg);
}
}
}
} else {
Log.d(
"loc",
":No GPS or network signal please fill the location manually!");
location = mlocManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
currentLocation = location;
Bundle b = new Bundle();
{
b.putBoolean("locationRetrieved", true);
{
Message msg = Message.obtain();
{
msg.setData(b);
mLocHandler.sendMessage(msg);
}
}
}
} else {
Bundle b = new Bundle();
{
b.putBoolean("locationRetrieved", false);
{
Message msg = Message.obtain();
{
msg.setData(b);
mLocHandler.sendMessage(msg);
}
}
}
}
}
}
}
call it like this
timer.schedule(new GetLastLocation(mLocHandler), 3000);
and the customLocationclass is as follows
public class CustomLocationListener implements LocationListener {
#Override
public void onLocationChanged(Location loc) {
loc.getLatitude();
loc.getLongitude();
currentLocation = loc;
String Text = "My current location is: " + "Latitud = "
+ loc.getLatitude() + "Longitud = " + loc.getLongitude();
Log.d("loc", "onLocationChanged" + Text);
}
#Override
public void onProviderDisabled(String provider) {}
#Override
public void onProviderEnabled(String provider) {}
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {}
}
If you are trying it out in a marshmallow device, try enabling location permission for your app manually.
turn on your GPS by using below method. it helps you to show your current location without any ERROR. call it in onCreate
public void displayLocationSettingsRequest(Context context, int requestCode) {
GoogleApiClient googleApiClient = new GoogleApiClient.Builder(context)
.addApi(LocationServices.API).build();
googleApiClient.connect();
LocationRequest locationRequest = LocationRequest.create();
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationRequest.setInterval(10000);
locationRequest.setFastestInterval(10000 / 2);
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(locationRequest);
builder.setAlwaysShow(true);
PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(googleApiClient, builder.build());
result.setResultCallback(result1 -> {
final Status status = result1.getStatus();
if (status.getStatusCode() == LocationSettingsStatusCodes.RESOLUTION_REQUIRED)
try {
status.startResolutionForResult((Activity) context, requestCode);
} catch (IntentSender.SendIntentException ignored) {
}
});
If you are getting a null error with your provider list, change...
List<String> providers = mLocationManager.getProviders(true);
to...
List<String> providers = locationManager.getAllProviders();
This worked for me, and make sure that you have the following in your AndroidManifest.xml file...
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Have you tried reversing the code? For example, if(location==null) then print that location is null, and else print location is not null. I got that problem once before and that seemed to have fixed it (i don't know why). Try that.
If that doesn't work, perhaps the google maps API is returning the null value, in which case its a problem with the GM-API or with the call method. Any of these could be the problem.

Categories

Resources