Longtitude and Lattitude not calculated (0.000000) (Location, GMAP Location)

Events happening in the community are now at Drupal community events on www.drupal.org.
imehesz's picture

hello everyone,

(although, I've created an issue ticket for this here http://drupal.org/node/670022, I'll ask you guys too)

I've seen some other (closed) tickets for this in the past (2008) but maybe it's a different issue. I created additional profile questions for my users (ie: firtsname and lastname) and enabled the location module (and the GMAP Location module).

I entered the GMAP API key,, so that should work just fine.

Here are my enabled modules:
GMAP, GMAP Location, Location, Location Search, User Locations, Profile

I also created the zipcode table (with a prefix!) and imported all the zip codes with the long and latt information.

So, when I create a user, it saves everything into the LOCATION table fine, but my lattitude and longtitude columns are always 0!

--iM

Comments

location_latlon_exact returns NULL

imehesz's picture

so far I found out that this function:

location_latlon_exact returns NULL ...

function location_latlon_exact($location = array()) {
  $country = $location['country'];
  location_standardize_country_code($country);
  $service = variable_get('location_geocode_'. $country, 'none');
  if (!empty($country) && $service != 'none') {
    // figure out what the exact function should be
    if (strpos($service, '|')) {
      location_load_country($country);
      // The code change below fixes the problem of the country specific
      // function for geocoding not being correctly called (it removes any
      // text from the pipe (|) onwards)
      $exact_latlon_function = 'location_geocode_'. $country .'_'. substr($service, 0, strpos($service, '|'));
    }
    else {
      location_load_geocoder($service);
      $exact_latlon_function = $service .'_geocode_location';
    }
    if (function_exists($exact_latlon_function)) {
      return $exact_latlon_function($location);
    }
    else {
      return NULL;
    }
  }
  return NULL;
}

and here $service is always NULL, meaning that the variable location_geocode_us doesn't exists :/

--iM

hack

imehesz's picture

well, I kind of fixed the problem ...

I've created a hook function in my module for _user and during the validation process, I check if the user's long or lat is 0.... if so, I use the gmap_geocode() function to get the coordinates by the address and just simply change the $edit array with the real coordinates.

It wouldn't be efficient with a large project (or if you have multiple addresses for one person), but in my case it will do the trick...

--iM

This will work great as long

chowdah's picture

This will work great as long as your user is not actually standing on the equator or the prime meridian!

Hi, could you share your code

summit's picture

Hi, could you share your code please?
Thanks a lot in advance!
Greetings, Martijn

Location and Mapping

Group organizers

Group categories

Wiki type

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: