Closed (fixed)
Project:
GMap Module
Version:
6.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
28 Jun 2006 at 15:42 UTC
Updated:
30 Jun 2008 at 20:28 UTC
I'm testing the CVS version of Gmap module. I try the geocoding feature but it don't works for me.
I try to insert in the Address text form a value that works at maps.google.com. I try to preview the new node and also to submit. In the location db table i see only NULL entries.
Comments
Comment #1
webgeer commentedWhat you have to do is enter a value into the geocoding field and then leave the field (by tabbing out or by clicking on something else). This will trigger the javascrip onChange event which will cause the geocoding to occur.
Comment #2
Lupin3rd commentedI find this two problems:
1) Changing address field when Lat/long fields have previous value displays 2 marker on the map for the new and previous locations.
2) Lat/long are the only fields written in the database. Name, street, additional, city, province, postal_code, country are all NULL, no matter what?
Comment #3
webgeer commented1) I am aware of this, it is a minor bug I have not been able to track down.
2) That is by design. If you need to store these items, location module is a more appropriate approach. This information is used only for geocoding a location, it is not stored anywhere. This is by design.
Comment #4
jamesJonas commentedHow do I turn on geocoding for nodes?
We have geocoding working for Users (good job). This uses the 'Coordinates' form generated by the gmap_location.module. This properly performs both address lookups and zipcode lookups using the gmap service after you enter the information inside the 'Address:' field and press tab.
When I create a new node or perform a node edit the 'Location' form appears. This is from is generated by the location.module. How do I get the 'Coordinates' form to apear inside node edit? The 'Coordinates' form includes the 'Address:' field used in geocoding.
Sample node edit: http://fatatlas.com/node/1576/edit
Thanks for a great module.
James
Comment #5
webgeer commentedTo use the Geocoding feature, you have to use the location setting function within gmap_location.module rather than the location setting function of location.module. Currently to do this, you have to disable the location.module. Then when you go to the admin/settings/content-types/acidfree page you can "allow users to set google maps info for this node type".
Comment #6
jamesJonas commentedThanks for the response.
I'm using the location_views module. When you disable the location.module you see this error:
"The module location_views was deactivated--it requires the following disabled/non-existant modules to function properly: location"
This was expected. I then disabled the dependency check inside the location_views .module. More errors. Well I guess I'm stuck with the location module.
How do I use geocoding for a node without disabling the location.module? Any ideas on work arounds, including hacks.
What is acidfree? It sounds like a custom content type.
"...go to the admin/settings/content-types/acidfree page you..."
James
Comment #7
jamesJonas commentedThere are quite a number of geocoding, location and setting functions inside the code. Which "location setting function of location.module" do you mean?
I have alread had to block several other functions in the code (Location Search (no taxonomy) and Geo Links (address centric versus lat/lon and address enabled)).
Comment #8
jamesJonas commentedGeocodeing works - Again
I have been able to get geocoding to work in the loaction.module for google. The country centric strategy that was necessary under the assumption that country specific zip code databases would be necessary no longer applies to the new geocoding environment. This means I still have some work ahead generalizing the geocoding in the locations module to world wide versus country specific. Combing the gmap.module with the geocoding in the location.module allowed me to relax the restrictions imposed by the location module that the returned lat/lon be aconstrained by a certain level of accuracy (rule:must be street level or no lat/lon returned).
Since google and yahoo can perform city level geocoding (you give city,state/province,country -> it returns lat/lon for city) for most of the developed world, this becomes a sufficient starting point for using a gmap map to refine the locations lat/lon. User inputs a city – gets a lat/lon that draws a map – user then uses the map to refine the location. Of course the map resolution issue still persists for many parts of the world, so there are limits to this strategy.
I still think there is a strong argument for migrating geocoding into is own module that provides an API to other modules. See 'geocode.module – why' http://groups.drupal.org/node/781#comment-3908
[not intended to be Anonymous, still figuring out how to contribute]
Comment #9
tomsci commentedGogman, well done! How you get it works? I have the same problem (i'm using gmap_views and can't disable location.module) but still can't find a way to fix it... your help would be actually appreciated.
thanx
Tom
Comment #10
jamesJonas commentedTom,
Thank you for your interest. The challenge for me is that the number of hacks I have had to perform across gmap_module, location.module, gmap_location.module, location.inc and location.us.inc are extensive.
I'm going to focus on changes to the file location.us.inc.
(1) change location_geocode_us_google_apikey TO googlemap_api_key
I'm running multiple sites that required me to work with multiple keys. The 'googlemap_api_key' is set for each website inside the sites folder. [drupal/sites/mysite.com/settings.php
$conf = array(
'googlemap_api_key' => 'AQIAAThisIsTheBigAPIKeyciA'
);
(2) changed 'function location_geocode_us_google' inside of 'location.us.inc'
function location_geocode_us_google($location = array()) {
$temp_key = 'ABQAAAA4SAAnotherBigKeyCeRNA';
$service_url = 'http://maps.google.com/maps/geo?output=xml&key='. // variable_get('location_geocode_us_google_apikey', '') .'&q=';
variable_get('googlemap_api_key', '') .'&q=';
(3) Eliminated the accuracy requirement inside the same function.
$accuracy_code = $accuracy_code_match[1];
// gogman - the requirement for accuracy at the address level is not required - user may then use map to refine lat/lon
/*
if ($accuracy_code != 8 && $accuracy_code != 7) {
return NULL;
}
*/
$latlon_match = array();
preg_match('/(.*)<\/coordinates>/', $http_reply->data, $latlon_match);
(4) changed key twice again again here:
function location_geocode_us_google_settings(){
$form = array();
// gogman
// $form['location_geocode_us_google_apikey'] = array(
$form['googlemap_api_key'] = array(
'#type' => 'textfield',
'#title' => t('Google Maps API Key'),
'#size' => 64,
'#maxlength' => 128,
'#default_value' => variable_get('googlemap_api_key', ''),
// '#default_value' => variable_get('location_geocode_us_google_apikey', ''),
// 'googlemap_api_key' - this is generalized key
'#description' => t('In order to use the Google Maps API geocoding web-service, you will need a Google Maps API Key. You can obtain one at the %sign_up_link for the %google_maps_api.', array('%sign_up_link' => 'sign-up page', '%google_maps_api' => 'Google Maps API'))
);
(5) for yahoo here are some untested changes:
function location_geocode_us_yahoo($location = array()) {
$service_url = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=". variable_get('location_geocode_us_yahoo_appid', "YahooDemo") ."&location=";
$address = location_address2singleline($location);
$http_reply = drupal_http_request($service_url . urlencode($address));
// address may have been improperly formatted or invalid
if ($http_reply->code == 400) {
return NULL;
}
else {
// got a successful reply, but we only want to return if we have address-level precision
// gogman - disagree - no address level precision is required
$matches = array();
preg_match('/precision="([a-z]*)"/', $http_reply->data, $matches);
/* gogman delete
if ($matches[1] != 'address') {
// The precision we got back was not down to the street-address level
return NULL;
}
else {
*/
$lat_match = array();
I hope this helps get you started. My next step is to generalize the location.us.inc file for world wide. The challenge is that this file contains a very valuable list of states (provinces) which is used in the location UI. Inside the location module settings you select which countries you wish to enable. This adds to the list of states/provinces that the user may select. Great for US only, but world wide - that dog don't hunt. The list is just to big. That section which assigns the state/province needs to be altered to be dependent on the country selected, which dynamically (ajax/js) changes the list based on a database call (requires a world wide state/province table).
You can see a sample of my code working here:
http://fatatlas.com/wiki/Sweet_Home_Alabama_1-1-1666
1) Change the from Birmingham to any other city in Alabama.
2) Delete the lat/lon (map will readajust dynamically - don't worry)
3) Hit submit.
4) change city back to Birmingham, delete lat/lon, hit submit (sorry, this demo does not reset automtically yet)
You may also try click/dragging the marker and see what happens.
Needed Improvements:
(1) single line entry of geocode which also populates location fields.
(2) submit is a scary way for the user to update the lat/lon. We need another button that the user may press to initiate a lat/lon update.
(3) need to postpone the updating of map positions until lat/lon are fully updated. Need better user feedback.
I'm not exactly sure if some other magic changes in my code corrected another part of this mistery problem. Remember, lots of other code has been changed. My broder recommendation is that a geocoding.module (or geocode.module) needs to be created which exposes an API that the location.module, gmap.module, event.module and location_views.module... could reuse. I'm right now trying to fix another part of my drupal mashup. Perhaps a future project.
gogman
Comment #11
tomsci commentedgoogman, you did a great work and that's why i'm interested. of course a geocoding.module would probably be the best solution, but what you did is already a big step.
also many many thanks for your post, i'll try to find the time to hack these modules the way you did... but i guess my few dev. skills wont help me ;)
cheers
Tom
Comment #12
bdragon commentedClosing, 4.7 era...