Posted by groovypower on July 13, 2008 at 9:54pm
Jump to:
| Project: | Location |
| Version: | 6.x-3.x-dev |
| Component: | Data update |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
| Issue tags: | location geo-coding |
Issue Summary
Does anyone know of a method to geocode the latitude and longitudes of a number of locations stored with just address data. I manually uploaded the addresses into the location and location_instance tables, but the only way I've determined to set the latitude/longitude is to edit the node the location is stored in and save a new revision.
Comments
#1
I am closing this out as there does not seem to be a need for this and I hacked together a solution for myself. Also, from the looks of Google's terms of use, any quick solution would probably have your API key disabled.
#2
I've always just used http://www.batchgeocode.com/...
#3
Where in Google's terms have you seen they prohibit bulk geocoding?
In fact they are encouraging you to bulk geocode with tutorials and such on their pages....
Also, I have not ever heard of someone having a disabled API key, just limited to how much, 100 000 geocodings per day?
#4
If its at all relevant, I used this code for a V5 install where I wanted to update some locations. The query does a check to confirm the location DOES have an associated node and that the location IS 0 (zero)...
It then loads the node, wipes the long and lat values, submits and saves.
<?php
$result = db_query('SELECT li.nid FROM {location} l LEFT JOIN {location_instance} li ON l.lid = li.lid WHERE li.nid IS NOT NULL AND l.latitude = 0');
while($row = db_fetch_object($result)) {
$node = node_load($row->nid);
$node->locations[0]['latitude'] = $node->locations[0]['longitude'] = $node->locations[0]['locpick']['user_latitude'] = $node->locations[0]['locpick']['user_longitude'] = '';
$node = node_submit($node);
node_save($node);
}
?>
On my VPS this did about 3,000 nodes in about 10 minutes.
I believe Google restricts each key to either 15,000 or 50,000 a day - I cant remember which off the top of my head.
#5
I'll mark this as fixed, as it seems to answer the original posters question.
Also, I'm tagging it geo-coding.
And it might be related to
#132541: refactor google geocoding
#6
popps. forgot to change status.
#7
I just noticed in my latest 6.x dev version, under the location settings, there is an option for:
Enable JIT geocoding
If you are going to be importing locations in bulk directly into the database, you may wish to enable JIT geocoding and load the locations with source set to 4 (LOCATION_LATLON_JIT_GEOCODING). The system will automatically geocode locations as they are loaded.
That seems related to this issue.
#8
marked #406048: Option to geocode all locations that lack lat/long as a duplicate of this issue
#9
Automatically closed -- issue fixed for 2 weeks with no activity.
#10
Google has a limitation of 15000 geocodes per day (per IP). If you need to geocode a very large number of addresses you could use http://www.bulkgeocoder.com.
#11
Subscribing
#12
You can also do this manually using the Location API. In the following code, I had a bunch of 'school' nodes with addresses but not lat/lon, so I get the lat/lon, set it, and save the node.
$query = "SELECT nid FROM {node} WHERE type='school'";$result = db_query($query);
while ($nid = db_result($result)) {
$node = node_load($nid);
$latlon = location_latlon_exact($node->location);
$node->locations[0]['latitude'] = $latlon['lat'];
$node->locations[0]['longitude'] = $latlon['lon'];
$node = node_submit($node);
node_save($node);
}
I saved that code as bulk_geocode.php in the drupal/ directory and ran drush php-script bulk_geocode.php.