I have written code in that if GPS is disabled it will be enabled by code and try to get Location from gps but I am getting a null value. Below is my code
public void getValue() {
LocationManager mlocManager = (LocationManager) MySettings.this.getSystemService(Context.LOCATION_SERVICE);
boolean gpsEnabled = mlocManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
System.out.println("GPS IS "+gpsEnabled);
if (!gpsEnabled) {
String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if (!provider.contains("gps")) { // if gps is disabled
final Intent poke = new Intent();
poke.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider");
poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
poke.setData(Uri.parse("3"));
sendBroadcast(poke);
}
}
SimpleDateFormat sdfDate = new SimpleDateFormat("MM/dd/yyyy");
try {
getBatteryLevel();
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, MySettings.this);
Location location = mlocManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
mLocation = location;
if (location != null) {
lat = location.getLatitude();
lon = location.getLongitude();
address = getAddress();
alt = location.getAltitude();
if (meterFootFlag) {
diameter = location.getAccuracy();
} else
diameter = location.getAccuracy() / 3.28084;
} else {
lat = 0.0;
lon = 0.0;
alt = 0.0;
}
} catch (Exception e) {
lat = 0.0;
lon = 0.0;
alt = 0.0;
}
Also I have added permission in manifest file
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
but I am getting a null value for the location.
Any ideas on how I can get the location?
Your code is correct just wait until GPs get altitude from a satellite it may take mroe than 1 minute.
try:
public Location showLocation(){
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
//Class model, save latitude and longitude
NavegadorCoordenadas locate = new NavegadorCoordenadas();
Criteria crit = new Criteria();
crit.setAccuracy(Criteria.ACCURACY_FINE);
String provider = lm.getBestProvider(crit, false);
Location loc = getLastKnownLocation(lm);
locate.setLatitude(loc.getLatitude());
locate.setLongitude(loc.getLongitude());
return loc;
}
private Location getLastKnownLocation(LocationManager location) {
List<String> providers = location.getProviders(true);
Location bestLocation = null;
for (String provider : providers) {
Location l = location.getLastKnownLocation(provider);
if (l == null) {
continue;
}
if (bestLocation == null || l.getAccuracy() < bestLocation.getAccuracy()) {
bestLocation = l;
}
}
if (bestLocation == null) {
return null;
}
return bestLocation;
}
Make sure that you are checking on DEVICE only.. In Emulator it will give Null Values for GPS as it is running in the system so it doesnot have permission for GPS
locationMangaer = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if(!provider.contains("gps")){ //if gps is disabled
final Intent poke = new Intent();
poke.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider");
poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
poke.setData(Uri.parse("3"));
sendBroadcast(poke);
}
locationListener = new MyLocationListener();
locationMangaer.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10, 10,
locationListener);
Now make MyLocationListener class in same activity.
private class MyLocationListener implements LocationListener {
#Override
public void onLocationChanged(Location loc) {
String longitude = "Longitude: " +loc.getLongitude();
String latitude = "Latitude: " +loc.getLatitude();
/*----------to get City-Name from coordinates ------------- */
String cityName=null;
Geocoder gcd = new Geocoder(getBaseContext(), Locale.getDefault());
List<Address> addresses;
try {
addresses = gcd.getFromLocation(loc.getLatitude(), loc.getLongitude(), 1);
if (addresses.size() > 0) {
System.out.println(addresses.get(0).getLocality());
cityName=addresses.get(0).getLocality();
System.out.println("MESSAGE:"+cityName);
}
} catch (IOException e) {
e.printStackTrace();
}
String s = longitude+"\n"+latitude+"\t city name:"+cityName;
Log.v("OUTPUT, s);
}
#Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
Run your application in Actual device.
you can figure out that automatic start GPS and see console logcat.
Make sure to open Permissions through the
Settings--> Applications-->YourApp-->permissions
And another reason could be delay, it takes time to connect to network, somethimes more than a minute
Related
I am trying to get the latitude and longitude of the current location using the following:
GoogleMap map;
map = ((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();
map.setMyLocationEnabled(true);
lat = map.getMyLocation().getLatitude();
lng = map.getMyLocation().getLongitude();
For some reason the last two lines are causing the app to crash due to a NullPointerException. What am I doing wrong?
The biggest thing that bugs me about this is the fact that map.setMyLocationEnabled(true); does indeed set my current location.
Thanks to anyone looking at this
Try this:
public Double Lat = null;
public Double Lng = null;
String LatLng = null;
private LocationClient mLocationClient;
in your onCreateView() add this
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.yourLayout, container, false);
mLocationClient = new LocationClient(getActivity(), this, this);
rootView.findViewById(R.id.ATestButton).setOnClickListener(
// Get the current location
Location currentLocation = mLocationClient.getLastLocation();
Lat = currentLocation.getLatitude();
Lng = currentLocation.getLongitude();
LatLng = Double.toString(Lat) + "," + Double.toString(Lng);
Toast.makeText(getActivity(), LatLng, 0).show();
});
Look at my complete github for a working example.
// I would a test button so can click it to see if anything is returned.
public void turnGPSOn() {
String provider = Settings.Secure.getString(getContentResolver(),
Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if (!provider.contains("gps")) {
final Intent poke = new Intent();
poke.setClassName("com.android.settings",
"com.android.settings.widget.SettingsAppWidgetProvider");
poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
poke.setData(Uri.parse("3"));
sendBroadcast(poke);
}
}
void getLocation()
{
locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (!locManager
.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
turnGPSOn();
}
try {
locManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 1000, 10,
locationListener);
} catch (Exception ex) {
}
}
}
private final LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
updateWithNewLocation(location);
}
public void onProviderDisabled(String provider) {
updateWithNewLocation(null);
}
public void onProviderEnabled(String provider) {
}
public void onStatusChanged(String provider, int status, Bundle extras) {
}
};
private void updateWithNewLocation(Location location) {
String latLongString = "";
try {
if (location != null) {
Log.e("test", "gps is on send");
latitude = Double.toString(location.getLatitude());
longitude = Double.toString(location.getLongitude());
Log.e("test", "location send");
latLongString = "Lat:" + latitude + "\nLong:" + longitude;
Log.w("CurrentLocLatLong", latLongString);
} else {
latLongString = "No location found";
}
} catch (Exception e) {
}
}
Your app is crashing because
map.getMyLocation()
returns null if there is no location data available.So you can have !=null check like this
if( map.getMyLocation() !=null){
lat = map.getMyLocation().getLatitude();
lng = map.getMyLocation().getLongitude();
}
Also this method is deprecated, so you should use FusedLocationProviderApi instead. See official documentation here
Here is a very good implementation of FusedLocation Api, you can check out that too.
map.getMyLocation() is null
you should check for that condition
I have found a solution. While I am still not sure why the other methods is giving me a null pointer, the below works just fine and will suit my needs.
LocationManager locman = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Location location = locman .getLastKnownLocation(LocationManager.GPS_PROVIDER);
double lng = location.getLongitude();
double lat = location.getLatitude();
I'm using new Google API for retrieving current location, and I got the current location. However, if the location services are not enabled in the app by default, and if I enable any location service using location intend, the client does not reconnect, in onActivityResult method, and I cannot fetch the current location.
public void onConnected(Bundle bundle) {
// TODO Auto-generated method stub
System.out.println(R.string.connected);
System.out.println("error");
startPeriodicUpdates();
if (mUpdatesRequested) {
startPeriodicUpdates();
}
if (!locationServiceEnabled)
return;
if(mLocationClient.isConnected()&& servicesConnected())
{
fetchlocation = new FetchingLocation(getActivity());
// mLocationClient = new LocationClient(getActivity(), this,this );
Location currentLocation = mLocationClient.getLastLocation();
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>" +
mLocationClient.getLastLocation());
latitude=currentLocation.getLatitude();
System.out.println(currentLocation.getLatitude());
System.out.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
+ String.valueOf(latitude));
}
else
{
}
}
But I can't get the location. As the app crashes, it shows the error:
client not connected wait for connect
Any ideas on how to solve this issue?
You have to get longitude and latitude value and then juste use that function
public String ConvertPointToLocation(GeoPoint point) {
String address = "";
Geocoder geoCoder = new Geocoder(
getBaseContext(), Locale.getDefault());
try {
List<Address> addresses = geoCoder.getFromLocation(
point.getLatitudeE6() / 1E6,
point.getLongitudeE6() / 1E6, 1);
if (addresses.size() > 0) {
for (int index = 0;
index < addresses.get(0).getMaxAddressLineIndex(); index++)
address += addresses.get(0).getAddressLine(index) + " ";
}
}
catch (IOException e) {
e.printStackTrace();
}
return address;
}
Refer to this tutorial
http://www.codeproject.com/Articles/112044/GPSLocator-App-to-Find-Current-Nearest-Location-us
public void setLatLong(double lat, double lng) {
Longitude = lng;
Latitude = lat;
}
public double getLatitude() {
return Latitude;
}
public double getLongitude() {
return Longitude;
}
public void getLocation() {
locManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
Utility obj = new Utility(context);
if (obj.isGPSAvailable() && obj.isInternetAvailable())
{
locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,0, locListener);
locManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,0, 0, locListener);
}
else
Toast.makeText(context, "Internet or GPS not available",
Toast.LENGTH_LONG).show();
if (locManager != null)
{
Location loc = locManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if(loc!=null)
{
setLatLong(loc.getLatitude(), loc.getLongitude());
}
else
{
loc = locManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if(loc!=null)
{
setLatLong(loc.getLatitude(), loc.getLongitude());
}
}
}
}
Use above code for retrieving current location and you could get more help # following link:
http://www.vogella.com/articles/AndroidGoogleMaps/article.html
I need to fetch locations or addresses of nearest location of a current gps location to show on google map.Currently i am able to show some locaions on map but that are hardcoded i need to fetch all nearest location before drawing the map.
Is there any suggestion?
Here is the way, that how can you achieve it.
LocationManager locationManager = (LocationManager) context
.getSystemService(Context.LOCATION_SERVICE);
LocationListener locationListener = new LocationListener() {
#Override
public void onStatusChanged(String provider, int status,
Bundle extras) {
}
#Override
public void onProviderEnabled(String provider) {
}
#Override
public void onProviderDisabled(String provider) {
}
#Override
public void onLocationChanged(Location location) {
Double l1 = location.getLatitude();
Double l2 = location.getLongitude();
address = GetAddress(l1, l2);
}
};
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
private String GetAddress(Double lat, Double lon) {
Geocoder geocoder = new Geocoder(context, Locale.ENGLISH);
String ret = "";
List<Address> addresses = null;
try {
addresses = geocoder.getFromLocation(lat, lon, 1);
if (!addresses.equals(null)) {
Address returnedAddress = addresses.get(0);
StringBuilder strReturnedAddress = new StringBuilder("\n");
for (int i = 0; i < returnedAddress.getMaxAddressLineIndex(); i++) {
strReturnedAddress
.append(returnedAddress.getAddressLine(i)).append(
"\n");
}
ret = "Around: " + strReturnedAddress.toString();
} else {
ret = "No Address returned!";
}
} catch (IOException e) {
e.printStackTrace();
ret = "Location: https://maps.google.co.in/maps?hl=en&q=" + lat
+ "," + lon;
} catch (NullPointerException e) {
e.printStackTrace();
ret = lat + "," + lon;
}
return ret;
}
And also add these permissions in AndroidManifest:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
First get your current location Lattitude & Longitude, then get Lattitude & Longitude of each locations you have and find out distance of each place from your current location using distanceTo method of Location class and after that find out least distance from your list.
A part of my app is attempting to update the location (using DDMS with an emulator in Eclipse) and then get the address to print to LogCat.
My code:
LocationManager locationManager;
String providerName = LocationManager.GPS_PROVIDER;
LocationProvider gpsProvider;
public void enable()
{
locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); //Need to ask for this system service
Criteria criteria = new Criteria(); //Setting the criteria for the location provider
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setPowerRequirement(Criteria.POWER_HIGH);
criteria.setAltitudeRequired(true);
criteria.setBearingRequired(true);
criteria.setSpeedRequired(true);
criteria.setCostAllowed(true);
String provider = LocationManager.GPS_PROVIDER;
int time = 5000; //Time in ms
int distance = 5; //Distance in meters
LocationListener myLocationListener = new LocationListener()
{
public void onLocationChanged(Location locations)
{
updateLocation(locations);
}
public void onProviderDisabled(String arg0)
{
// TODO Auto-generated method stub
}
public void onProviderEnabled(String arg0)
{
// TODO Auto-generated method stub
}
public void onStatusChanged(String arg0, int arg1, Bundle arg2)
{
// TODO Auto-generated method stub
}
};
locationManager.requestLocationUpdates(provider, time, distance, myLocationListener);
}
/////////////////////////////////////////////////////////////////////////////////
public void findLocation()
{
gpsProvider = locationManager.getProvider(providerName);
//String bestProvider = locationManager.getBestProvider(criteria, true);
Location locations = locationManager.getLastKnownLocation(providerName);
updateLocation(locations);
}
public void updateLocation(Location locations)
{
if (locations != null)
{
Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.getDefault());
double latitude = locations.getLatitude();
double longitude = locations.getLongitude();
List<Address> addresses = null;
Geocoder GCoder = new Geocoder(this, Locale.getDefault());
try
{
addresses = GCoder.getFromLocation(latitude, longitude, 10);
Address first = addresses.get(0);
Log.d("ADDRESS", first.toString());
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
This, to me, should print the value "first" into LogCat but it doesn't seem to actually display anything.
I have the required permission in the manifest so that is not the issue.
Any help that can be provided is great, thank you.
Use this code
See Updated Code
LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
String provider = locationManager.getBestProvider(new Criteria(), true);
Location locations = locationManager.getLastKnownLocation(provider);
List<String> providerList = locationManager.getAllProviders();
if(null!=locations && null!=providerList && providerList.size()>0){
double longitude = locations.getLongitude();
double latitude = locations.getLatitude();
Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.getDefault());
try {
List<Address> listAddresses = geocoder.getFromLocation(latitude, longitude, 1);
if(null!=listAddresses&&listAddresses.size()>0){
String _Location = listAddresses.get(0).getAddressLine(1);
}
} catch (IOException e) {
e.printStackTrace();
}
}
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.