I am using location + gmap on my site and it works but is quite clunky. You have to submit a node in order for it to geocode which requires re-editing it if the geocoding failed. Plus, the only way I found to allow multiple locations was to have multiple forms and maps from the get go. (The setting "Add another location from node view page" doesn't work.) This is extremely cluttered since most of mine would need only one location but some may need 10. I would like it to be a lot simpler since my users may not all be computer people. Unfortunately, I don't have the skills to do this so I'm having to put this in as a feature request and hope someone can do it.

This is how (IMO) it should work:

1) User is presented with one location form to fill out with a map underneath it.
2) Geocoding is done one of three ways:
a) User can click "map it" button and the site will attempt to geocode the address. If successful, a marker appears on the map and the lat/long are filled in. If not, a warning pops up.
b) User can locate the point on the map manually and the lat/long are filled in automatically.
c) User can enter lat/long and the marker appears on the map.

Changing the marker position should change the lat/long and vice versa. Neither changing the marker position nor the lat/long should change the address, but changes to the address followed by clicking the "map it" button should update the other two.

3) To add another location, the user should click the "add another location" button. This would spit out another form including lat/long but not another map. This second location would add a second marker to the same map. Repeat for as many locations as allowed in settings.

Thanks,

Michelle

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

swill’s picture

working on this. hopefully will have some code available for you in the next couple days...

swill’s picture

FileSize
1.34 KB

hey michelle,
i didnt have much time to work on this yet, but here is a small module that is a start at least. i have not tested it with multiple locations, but i coded it with the intention that it should work with multi locations. i have also not added any settings for it either, so you will have to change the name of the link and the description (and layout) in the module its self. I tried to design it so that we would have a lot of css style control.

keep in mind this is just the start of this module, but i didnt know how urgently you needed this functionality and how much you wanted to customize it anyway.

let me know if you have problems, ideas or any feedback at all...

swill

ps - having trouble uploading the file. it is a 'zip' file. rename it from .txt to .zip and then extract it...

swill’s picture

FileSize
1.52 KB

Alright, as you pointed out via IRC the above module assumes that you are using the country drop down and fails if you are not.

I have rewritten it to not make any assumptions about what fields you are entering. This should now work for almost all countries with the exception of maybe the UK, Liechtenstein, and maybe Austria... I will look into fixing that, but this will probably work for you.

Any feedback is requested. I am not having it pop up the info box for the location it finds, but its just commented out if you want to add it.

again, the .txt file is actually a .zip file, so rename it and extract it...

cheers...

Michelle’s picture

I'm still getting the same error. To be sure I didn't have remanents of the old module, I deactivated the module, deleted the files off my server, cleared my cache, redownloaded the file, and started over. I'm still getting this:

country_object.selectedIndex has no properties
http://example.com/sites/all/modules/map_location/map_location.js
Line 5

Just to be clear, I'm not only not filling out the country field, I don't even have the country field there at all.

Thanks,

Michelle

swill’s picture

FileSize
2.4 KB

the problem was that the input field is only hidden, so my check to see if it existed showed that it did still exist. my bad...

that should be fixed now. i have also added a css file and added a setting section for it so you can customize it to your liking. it should now work for all counties as well.

let me know how it works...

the file is a zip. rename it and extract to use...

swill’s picture

FileSize
2.45 KB

ok, just for completeness i have made sure that the lat and lng cords are written into the form so that regardless of how you build the map after the form is submitted it should work.

cheers,

swill

ps - its a zip, rename and extract...

Michelle’s picture

I just found a problem with the module... I've lost the ability to manually place a marker on the map now. Is the js conflicting?

Thanks,

Michelle

Michelle’s picture

Submitted to soon. I tried tweaking the lat/long to get the marker where I want it and that no longer works, either.

Michelle

swill’s picture

i will check into that. sorry i have been having a bit of a crazy couple weeks...

swill’s picture

FileSize
3.19 KB

I have added the listeners that this module had accidentally removed. i did not make the functionality 'exactly' like it is for the clicking on the map without clicking the map_location link. the reason is that i dont really like the way it zooms and centers (its faster and cleaner not to).

i have changed the functionality so that:
- if you do not click on Map Location, nothing changes
- if you click on map location then you will get the marker (and the lat/long info for the marker will be added to the location form)
- if you click somewhere else on the map after you have clicked Map Location, the marker will be moved and the lat/long (location form) will be updated
- if you click on a marker once the Map Location has been clicked, then the marker will be removed
- if there is no marker (you removed it) after clicking Map Location, then if you click somewhere on the map, a marker will be added and the lat/long info will be updated...

i think this takes care of our problem. let me know...

ps - have you tested this at all with multiple locations? i attempted to code it for multi locations, but i have not tested it at all. any feedback in that regards would be appreciated.

Note: file is a zip file, rename and extract..

swill’s picture

for completeness; if you click on a marker to remove it once the Map Location link has been clicked, the marker is removed and the lat/long info in the location form is also removed...

Michelle’s picture

Awesome!

Works perfectly and is a much needed improvement to the UI.

Michelle

catch’s picture

Status: Active » Needs review

Just bumping status to get this some attention. Not tried it yet but great ideas!

jonnyp’s picture

This is excellent - having just downloaded the latest location module with UK geocoding, and then modifying it to get a 'best match' on unsupported countries I was wondering if I could use the best match and then edit the location with gmap when i found this - but a live geocoding without having to save the node is fantastic!

My only comment for improvement is that your settings page does not use variable_get to find what the link title and description have been set to, but revert to the defaults when you return to the settings page - a minor issue tho, i think the functionality of this is brilliant.

smitty’s picture

FileSize
11.08 KB

Thank you, swill, for this wonderful solution. I think, you should provide it as an independent module. It is too great to be hidden in an issue of the location module!

Nonetheless I have some remarks for further development:

When I started testing, this module did not work for me. I entered valid addresses, but the module told me: "’address’ not found".

I fiddled about with the addresses and found out, that the geocoding does not work, when you have some data in the Field “State/Province”. That’s no surprise, because the location module holds the data of this field in a normalized way: so for “New York” the field contains “us-NY” instead of “New York”, what is displayed at the surface.

So I wrote the function “translate_province” and called it in the address_to_string-functions to change the token to the full province name (please have a look at the attached js-file).

Now it works for me. But it works only for Germany, because I only used the provinces of my home-country.

To get it working for the rest of the countries of the world you would have to enhance the function with the equivalent information, which would be a lot of work to do.

And furthermore this would be redundant, because all of this is already in the inc-files for the supported counties of the location module (folder supported). So I wonder whether it might be possible to call a function of the location module to do this work.

Sadly I am a beginner in coding for Drupal and especially java script. So I do not know if it is possible to call a Drupal-function from the java script. But I assume that’s not feasible.

My second remark is that in the whole java script dos a lot of work, which is already done by the location module (in the google.inc). So I wonder whether it is possible to use this instead of doing the whole work twice.

Especially there are differences among the google.inc and the map_location.js. For example in the google.inc the geocoding is only allowed for 23 countries (I do not know why!) while in the map_location.js there is no such restriction.

The third point is, that the location-map module does not use the settings of the location module, for example to show the map controls or to adjust the zoom factor. The only way I found to switch on the map controls was to put it directly into the java script. But that way you have to change the code every time you want to change the appearance of the map and you have to do it twice: in the location settings and in the map_location.js.

Is there anybody who can help to avoid this problems?

Michelle’s picture

You don't need to worry about adding US states to the JS. It works just fine as is with those. I don't know what you mean about the map. It has the controls for me just like it always did.

As for the redundant code, I'll leave that discussion up to Swill because I don't know anything about JS.

Michelle

smitty’s picture

FileSize
48.24 KB

Well, am I doing something wrong, then? Every time I try to geocode an address with the province set, I get a "not found" error, like the one you can see in the attachment.

Ok, the map may look like the defaults you used in the location/gmap module up to now. But if you want to change something in the settings (e.g. switch off the type-control) you cannot do it in the settings of the gmap module or in a macro, but you have to change the js.

Michelle’s picture

I put in my address, including Wisconsin, and it geocodes it just fine. I also went into gmap and turned off the control and that worked as well.

Michelle

swill’s picture

i have an idea why this is happening. the other people who are using it in the US do not have 'Country' enabled, so i didnt get this situation in my testing. i will try to fix it and get you an update, but it may not happen till monday...

cheers,

will

smitty’s picture

@Michelle:

Thanks for testing. You are right. If you turn off the control and go to the page with the location on it, you will not see control any more - because what you then see comes from the location module.
But if you next click on the link "Map this location", the map will change and show the control again, because now the map_location module takes over and there it is hard-coded in the js.

@swill:

I am looking forward to your solution. I did some more testing and saw that cutting off the first tree characters of the province string (that means converting us-NY to NY) solves the problem. But regrettably this works only for the US and Canada (probably for some other countries too), but not for the whole world. The problem seems to be, that google does not understand the ISO-code 3166-2 neither the standard with five or six characters nor the part of the province-code. So translating according to the location.countrycode.inc's seems the only correct solution to me. What do you think?

swill’s picture

yes that is the problem. google only expects the region, not the country-region value. i was going to just remove the first 3 chars of the province/state value since it is of the form [country-region] and all the country codes are 2 letters. since we are doing this in javascript, we do not have access to the country specific inc's, but this should work. I have been getting worked to the bone recently and my todos are nuts right now... i will try to get it done by the end of the week. sorry for the delay...

mlncn’s picture

This would be great timing for the World Social Forum 2008 (actions all over the world) site!

kjl’s picture

The fix is simply replacing each instance of

address = address+province_object.options[province_object.selectedIndex].value;

with

partial = province_object.options[province_object.selectedIndex].value
address = address+partial.substring(3);

in map_location.js

swill’s picture

FileSize
5.86 KB

thanks kjl for making it easy for me to just throw this together and get it out for you guys without having to make any time for it...

here is the update. i have tested it for a couple addresses and it is working for me. let me know if you have problems...

note: rename the file to .zip and extract.

will

smitty’s picture

FileSize
3.6 KB

Thank you swill and kjl for this solution. This works fine for the US and Canada and probably for a couple of other countries. But I’m afraid it does not work for all countries. For example:

With Street: Tunnelstraße, City: Norden, Province: Niedersachsen, Country: Germany you get a “not found”-error. With City: Brest, Province: Finistere – Bretagne, Country: France and with City: Belfort, Province: Haute-Saone – Territoire de Belfort you get lost somewhere in space (first example: Provence, second example: area of Bordeaux), but the map will not show the right cities. Google seems not to know all of the ISO-code 3166-2 tokens.

So I reengineered my former solution and added two functions to the map_location.module, which build an array of the provinces (using the inc-files oft the location-module) and insert it into the javascript. I also enhanced the translation function in the map_location.js. It now cuts off the first the characters of the country-province-token, if the actual province is not in the array. So I hope this should work for most countries of the world.

Regarding the problem with the settings I replaced the “map = new GMap2()” with “map = Drupal.gmap.getMap” in map_location.js, so that the map is used, which the location-module already inserted into the node, instead of adding a new one. Now all the settings of the location module are used and the look and feel is exactly the same as of the location module.

While testing with multiple Locations in one node I found that the Element-IDs of the gmap-fields are numbered differently to the location-fields. So I replaced ‘”gmap-loc1-locpick_latitude”+count’ with ‘gmap-loc”+locnr+”locpick_latitude0”’.

Finally I tried to get the condition for the insertion of the “, “ in the address_to_string functions a little bit slimmer.

While testing this solution I found two issues:

  • When adding a marker using the link “map this location”, it is no longer possible to remove this marker by clicking on it. This action causes a javascript-error (but it is possible to switch it to another position and remove it afterwards).
  • When adding a marker using the link “map this location”, it is not possible to remove this marker by deleting the coordinates in the Latitude/Longitude-Fields (but it is possible to switch the marker to another position and remove it afterwards by deleting the coordinates). But this is no new problem: It also occurred in the unchanged version of this module.

I assume there must be a problem with the way of inserting this marker, but I didn’t find anything to do it different (Calling the function Drupal.gmap.factory.marker(point) causes the same problem). Perhaps someone with a better knowledge of the location module can help (for me as a beginner the code of the gmap.js is quite difficult to understand)?

I hope this helps a little. Please tell me, what do you thing of this solution and if it works for you too. Please feel free to review and improve the code.

Note: please rename the file to .zip and extract.

swill’s picture

@smitty - thanks for taking the time to try to improve this module/snippet/thing. it started out as a simple way for michelle and i to solve this problem and has been evolving a lot thanks to the suggestions, code and help you all have been offering.

i have been very busy recently with a site that is currently in alpha, but i will try to set aside some time to review your changes and see if i can solve the noted problems.

thanks again...

will

smitty’s picture

To get the little bug fixed, which was mentioned by jonnyp, in the function map_location_admin_settings() you just have to replace

'#default_value' => t('Map this location'),
with
'#default_value' => variable_get('map_location_link_value', t('Map this location')),

and
'#default_value' => t(' - click to place a marker on the map'),
with
'#default_value' => variable_get('map_location_desc_value', t(' - click to place a marker on the map')),

Crimson’s picture

Oh sweet, a very nice little module here. I wonder if you can make this more general for hooking into profiles/user registration without the location module.

cday119’s picture

Where do I put the files in the zip file?

scottrigby’s picture

subscribe (and sorry everyone, if there's a better way to subscribe - if there is, it's not intuitive!) - thanks

Michelle’s picture

cday119 - Put it with your other modules. Usually sites/all/modules

scotrigby - Unfortunately, there's not. :(

Michelle

scottrigby’s picture

Hi
I added this issue separately, because it relates to this "Map Location" module, and also Location more generally.
http://drupal.org/node/191122

But see what you think -- it's definitely related to this discussion

Thanks for suggestions!

Summit’s picture

subscribing.
greetings,
Martijn

nicholas_w’s picture

I thought I was totally going to have to patch/program this myself -- it's essential when you're going to let users create geocoded nodes. I've installed the module and it seems to be working well. Thanks to everyone who worked on it.

AlexPenfold’s picture

Subscribe.

Alex Oliver Perez’s picture

hi guys thanks for this wonderful snippet it really help me out.. :)

greetings,
Alex Oliver

raymondllee’s picture

subscribing

tanoshimi’s picture

subscribe!

cday119’s picture

Check here for a reverse geocoding function. This is if you want a user to click on a GMap and get the address of where they clicked.

sandman’s picture

This module has a problem: if it's executed before the location module, it doesn't work.

I had to install module weight to set an higher weight to this module.

Anyway, it's very cool! Thanks, it's exactly what I need!

cosmicdreams’s picture

in addition, I like this change to the location.theme file:

function theme_location_form(&$form) {
  foreach (element_children($form) as $field_name) {
    $row = array();
    if ($form[$field_name]['#type'] == 'markup') {
      $row[] = array('data' => $form[$field_name]['#value'], 'colspan' => 2);
    }
    elseif ($form[$field_name]['#type'] != 'hidden') {
      $required = !empty($form[$field_name]['#required']) ? '<span class="form-required" title="'. t('This field is required.') .'">*</span>' : '';
+      if ($form[$field_name]['#id'] != '') {      
+      $row[] = array('align' => 'right', 'data' => '<div class="form-item"><label'. (' for="'. $form[$field_name]['#id'] .'" ') .'>'. 
+	       filter_xss_admin($form[$field_name]['#title']) .": $required</label></div>");
+ 	       unset($form[$field_name]['#title']);
+      $description = $form[$field_name]['#description'];
+      $row[] = array('align' => 'left', 'data' => drupal_render($form[$field_name]));
+      }
+      else{
+      $description = $form[$field_name]['#description'];
+      $row[] = array('colspan' => '2', 'align' => 'left', 'data' => drupal_render($form[$field_name]));
+      }
      $rows[] = array(
        'data' => $row,
        //'class' => 'odd' //optional
      );
    }
  }

This code removes the extraneous left cell in cases where there is no field title, like when the Gmap is displayed. When you set the width of the Gmap to 100% then the map will be the width of the whole location submission table.

now if I could only hide the latitude and longitude fields I'd be perfectly happy.

pkej’s picture

> now if I could only hide the latitude and longitude fields I'd be perfectly happy.

Can't you just do some css magic for that? Set the elements/rows to hidden.

yeeloon’s picture

subscribing

scottrigby’s picture

>> now if I could only hide the latitude and longitude fields I'd be perfectly happy.

> Can't you just do some css magic for that? Set the elements/rows to hidden.

Unfortunately there's no unique classes or IDs for these fields. I've tried all the CSS magic that I know, but to hide these you'd have to hide other fields that also share the same class. Not great. Also, if the access to submitting Lat & Lon is turned off, then users have ot submit their node twice before the geocoding kicks in (in short - to get the map to work in a user-friendly way, users NEED to have permission to add latitude & Longitude, but it works just as well if these are not used - so having a way to hide them would be SO great!).

What is the appropriate way to add unique classes / IDs to forms that don't have them? (would have to include the label as well)? If I knew how to do this I'd add classes to the forms and figure out how to submit a patch!

Any advice about that?

PS, I know this may seem like water under the bridge now that D6 has come out, and BDragon is working on Location 3... but it would be really great to have some way of dealing with this in the meantime.

Thanks in advance to anyone who has advice about this
:)
Scott

pkej’s picture

There is a lot going on for D6, but without CCK, Views and Panels ready for D6, most people will have to stick with D5 for a long while.

ultimike’s picture

Great addition to Drupal's location/GMap universe.

How about adding this as an official Drupal module to give it a bit more exposure? I can't see how everybody who uses gmap_locations wouldn't want this functionality - perhaps you should add it as a patch to the GMap module...

-mike

Wouter Van den Bosch’s picture

Subscribing.

Works great for me. Cheers !

thePanz’s picture

Is there a way to use default drag'n drop functionality for marker like Google does in GMaps? I mean: I can grab the marker and drop where I like, with no need of click and then click again to re-position it..

Regards

adshill’s picture

This is fantastic - tested and works like a dream on UK, however you have to disable province field in location. On saying that the province field for UK in location module is pretty useless anyway - should be counties not cities.

Anyway - thanks for the work and hope you either get this as a stand alone module or as a contrib in gmap as its a bit hidden away here in this thread!

adshill’s picture

I'd suggest asking this question in the gmap module forum as its not really related to this thread.

thePanz’s picture

Ok, I'll ask there! :)

CoolDreamZ’s picture

Fantastic! subscribing....

dannyp’s picture

scottrigby, where are you trying to hide it?

You can probably hide it just fine with CSS, just specify in what context it should be hidden. I removed the latitude and longitude from the HTML infobox on my ppcmap view like so:

div.view-ppcmap .latitude, div.view-ppcmap .longitude {
display: none;
}

Obviously you need to specify which view you want to hide it on... if you had more than one, it might be worth finding a parent of view-ppcmap or a different selector instead. Firebug is your friend!

scottrigby’s picture

I understand what you mean dannyp -- but I'm not still trying to hide the presentation...

It's the entry/edit form that's my problem. On this particular site I'm working on, users who are entering a location don't need or want to specify Latitude & Longitude. This gets taken care of automatically... So I just want to hide those fields from the edit form without having to create a new form template for every content type (which I'd then have to update with each new CCK field)...

Like I say above - I know there's an option in user access to limit a user's ability to enter Latitude & Longitude (which I've tried), but when that's the case the node doesn't automatically pick up the placement on the map unless the user clicks edit and save again. Big time annoyance which no site should ask of it's users...

Thanks anyway, but until I learn how to add unique classes or IDs to the Lon & Lat fields (or until someone helps with this), there's no way to hide these fields :(

MGParisi’s picture

subscribe

This looks very interesting:)

First, every time a user clicks it zooms in. On any map using satalite data, if you keep moving the icon, it will eventually zoom past the images provided:(

Also swill says he is not using this module, can someone take on this module and add it to the module page? I would, except that this is above my head :(

scottrigby’s picture

For now, I've solved my problem using hook_form_alter

It's not ideal, since the Latitude & Longitude fields are now represented by a colon (the only thing I can't hide yet!)... but it's still much better than users having to see these fields (or else not being able to automatically generate a map from their location on first submit).

Here's what I did:
in a custom mod (sitename.module) I added:

function sitename_form_alter($form_id, &$form) {
  switch ($form_id) {
    // loop through all the content-types we which contain Lon & Lat fields we want to hide
    case ('my_content_type_node_form'):
    case ('another_content_type_node_form'):
      // Hide the title, and wrap css-hidden div around Latitude & Longitude fields
      $form ['locations']['0']['latitude']['#title'] = t('');
      $form ['locations']['0']['latitude']['#prefix'] = '<div style="visibility:hidden; display:none;">';
      $form ['locations']['0']['latitude']['#suffix'] = '</div>';
      $form ['locations']['0']['longitude']['#title'] = t('');
      $form ['locations']['0']['longitude']['#prefix'] = '<div style="visibility:hidden; display:none;">';
      $form ['locations']['0']['longitude']['#suffix'] = '</div>';
      // This is in case we add more forms later
      break;
  }
}

Adding a css-hidden div beginning & end using the prefix & suffix works for the field itself, but the tile remained :(
So I added the t('') to remove the title, and that seems to work :)
As I said, the fields still show the ':' that was between the two, but this is the best I could do for our site so far.
Hope it helps someone else out who needs the same thing (until the issue is solved in a better way)...

Scott

Michelle’s picture

"can someone take on this module and add it to the module page?"

Please don't. There are already enough mapping related modules. Splitting this small bit of UI for location into a totally separate project makes no sense. It needs to be comitted to location, not split off.

Michelle

bdragon’s picture

Blargh, apparently I need to pay more attention to this issue.

swill’s picture

i apologize for not keeping up with this thread. this was a piece of code that i wrote to help simplify the mapping functionality and Michelle needed it too, so this thread was born.

the reason i have not been supporting this code is because i no longer use it. i have since changed my mapping functionality quite a bit in order to have a simpler interface for my users. if you want to see what i am using now, you can check it out here: http://groups.drupal.org/node/11324

bdragon has helped me a lot with my mapping implementation, so i have a pretty solid understanding of the mapping code now, if you need a hand you can contact me and we can meet up in an IRC channel to try to work through some of your issues. cheers...

ron_s’s picture

@scottrigby -- I've read your posts, and I'm really confused why what you're trying to do can't be done with some CSS and theming? For every edit form, all I did was the following:

#id_edit-locations-0-latitude, #id_edit-locations-0-longitude { display: none; }

Or whatever ID your Location fields might be in your CSS file. Then copy from location.theme the function theme_location_form(&$form) and put it in template.php, rename it to your_theme_name_location_form(&$form) (where obviously "your_theme_name" is the name of the theme you're using), and insert the following line right beneath $row = array();:

if ($form[$field_name]['#title'] != 'Latitude' && $form[$field_name]['#title'] != 'Longitude') {

You'll then close the conditional statement after the elseif ($form[$field_name]['#type'] != 'hidden') { section (basically the IF above contains the entire if/elseif that's already there). Works like a charm.

Ajenjo’s picture

Hi.

Fist of all, congratulations for this module.

Now, I have two questions.

1.- How can I show the location in a specific place in the page??? The map shows at the end of node form (hook_form) but I want draw it next to a field named 'direction' (Avobe and behind it there are more fileds).

The next question isn't specific of module map_location, but I hope you reply me...
2.- When I click over a mark (in the map) the zoom is too high and takes another location as a center, not the node. I wrote the gmap settings in other location instead the default, but I don´t think that this is the cause because in the section 'node locations' occurs the same.

Sorry if I said some nonsense or for my poor english.

Thanks.

bdragon’s picture

Version: 5.x-1.x-dev » 6.x-3.x-dev

I'd be really interested in a 3.x version of this work ;)

jasontanner’s picture

I tried the patch above in v3 (as a separate module: map_location) and although with debugging turned on I can see it entering the alter_form hook and it definitely is modifying the $form variable - it does not add anything to the form when its rendered.

I have also tried changing the weight of the map_location module to be 50 so is definitely higher than most things and also clearing the cache etc.

I am reasonably knowledgeable about PHP but I know very little about the drupal internals and so do not feel confident in making a v3 version of this myself.

Michelle’s picture

It won't work with V3 as is because he's changed that whole section including removing the table.

Michelle

catch’s picture

Status: Needs review » Needs work
giorgio79’s picture

Hi,

I just found this patch for geocoding. Would you know how it compares with Google Client Geocoder module?

www.drupal.org/project/gcg

priyasarathy’s picture

Hi,
I am probably missing something that I am staring at, but can someone please point me to the 'location' and 'gmap' module that needs to be installed for the code in comment #10 to work. When I search the module section there are so many modules with similar names. I currently installed the code in #10 and the google maps location module. THe message I get is at the module page is:

Google Maps location 5.x-1.0-1 Display one geographic location via Google Maps
Map Location 5.x-1.x-dev This module adds a link below the location address and above the gmap that geocodes the address and places a marker on the gmap
Depends on: Location (missing), Gmap (missing)

Thanks for the help.

Priya

Michelle’s picture

@priyasarathy - Well, you're in the location queue, so that's simply a matter of clicking the breadcrumb... Gmap is at http://drupal.org/project/gmap but it's all pretty moot, anyway, considering this patch doesn't work anymore as I mentioned in #64.

Michelle

priyasarathy’s picture

Thanks Michelle.

Do you know of any module/modules that would show multiple locations on a single map, and multiple maps can be generated for various posts?

Priya

Michelle’s picture

@priyasarathy I use location/gmap for all my mapping. You can show multiple locations on a single map with a view. I don't know about multiple maps for a single node. This is really off topic for this issue, though.

Michelle

kobnim’s picture

Version: 6.x-3.x-dev » 5.x-3.0-test2

Hi All,
I'm having difficulty figuring out how to theme the location form. Specifically I would like to hide the latitude and longitude input fields. I see that both scottrigby(#56) and ron_s(#60) have suggested solutions, but I have not been able to get their solutions to work. I am using version 5.x-3.0-test2.

1. Why scottrigby's form_alter solution is not working for me:
In my version of the code (5.x-3.0-test2), it seems that the latitude and longitude input fields are created after form_alter is called. It looks like these form fields are inserted by hook_elements, which sets a callback to the function (_location_expand_location) that adds the input fields.

/**
 * Implementation of hook_elements().
 */
function location_elements() {
  return array(
    'location_element' => array(
      '#input' => TRUE,
     '#process' => array('_location_expand_location' => array()), 
      '#tree' => TRUE,
      '#location_settings' => array(),
      '#attributes' => array('class' => 'location'),
      // Element level validation.
      '#validate' => array('location_element_validate' => array()), 
    ),
   ...
  );
}

I then tried overriding this theme function:

/**
 * Theme function to fixup location elements.
 */
function theme_location_element($element) {
  // Prevent spurious "Array" from appearing.
  unset($element['#value']);
  return theme('fieldset', $element);
}

with the following function:

function phptemplate_location_element($element) {
  // Prevent spurious "Array" from appearing.
  unset($element['#value']);
  $element['locpick']['user_longitude']['#type'] = 'hidden';
  $element['locpick']['user_latitude']['#type'] = 'hidden';
  return theme('fieldset', $element);
}

But for reasons I can't figure out, none of my customizations "take".
It's as though some other function, not theme('fieldset',$element), is responsible for outputting the html.

Can anyone point me in a more fruitful direction, or clear up some of my confusion around how theming works in the location module?

2. Why the solution proposed by ron_s (#60) is not working for me:
There is no theme_location_form() function in my version of location.module.

Thanks for your help,
Mindy

kobnim’s picture

A postscript to my previous message:

When I said "There is no theme_location_form() function in my version of location.module" ...
I found the function inside location_search.module.

That's the good news.
The bad news is ...
I don't think this function is getting executed -- my print_r statements don't show up on output. So I'm back to square 1.

Any insight greatly appreciated.
- Mindy

bobdalob’s picture

Re:#64

It won't work with V3 as is because he's changed that whole section including removing the table

I was pleased to find this topic, then disappointed to see that the mini-module is now redundant for active versions.

Is this translatable this for use with V3? It should really be built-in for users of Location+Gmap.

bobdalob’s picture

In fact by not placing a marker, a "Request for invalid marker set [small gray]!" error occurs when editing a node where the address was entered in place of placing a marker.

Edit: I'd just like to refer to the node map module which implements location submission/editing really well however it doesn't yet have the scope for utilising the data (e.g a map showing the location of nodes, taxonomy markers etc. as when location API is used with the gmap module).

kobnim’s picture

Following up from my earlier post (#71), here is what I ended up doing to hide the latitude and longitude input fields:

A. form_alter()
In form_alter(), I added an '#after_build' callback function.

$form['#after_build'][]='mymodule_after_build_mynode';

B. callback
Here is the callback function.

function mymodule_after_build_mynode($form, $form_values) {

	// hide latitude or longitude input fields
	$form['locations'][0]['locpick']['user_latitude']['#type'] = 'hidden';
	$form['locations'][0]['locpick']['user_longitude']['#type'] = 'hidden';
	
	return $form;
}

- Mindy

bdragon’s picture

Version: 5.x-3.0-test2 » 5.x-3.x-dev
bdragon’s picture

Title: Improve UI for entering and geocoding of locations » [master]Improve UI for entering and geocoding of locations

Blessing issue and marking former master #231419: [meta] Rewrite the location entry UI obsolete.

bdragon’s picture

Version: 5.x-3.x-dev » 6.x-3.x-dev
Summit’s picture

Subscribing.
Greetings, Martijn

lpt6’s picture

subscribe

kkrgopalan’s picture

subscribing

SocialNicheGuru’s picture

subscribing

Clown69’s picture

Is it possible to get the lat/lon data after entering an address without prior saving the node. The map_location module by swill which seems to provide this function doesn't work with 6.x.

YesCT’s picture

YesCT’s picture

Issue tags: +location Master Issues

Tagging.

arton’s picture

subscribe

Does anybody have any idea if this is working it's way into the location module?
It seems from the comments that it was fairly easy to implement, and there seems to be lots of interest in it.
I sort of assumed that it would do so automatically and was pretty frustrated testing Distance/Proximity filtering until I realized I needed to manually enter the coordinates.

This would be a great addition!

YesCT’s picture

Issue tags: +location geo-coding

opps. forgot to tag, when I said tagging.

psynaptic’s picture

Can a collection setting be added to the content type admin area to control the display of longitude and latitude? I'll use hook_form_alter for now but would prefer it if there was an option in the UI.

eff_shaped’s picture

subscribing

cerup’s picture

subscribing

riversidekid’s picture

Subscribing

kvvnn’s picture

subscribing

jrao’s picture

subscribe

jfev’s picture

subscribe

held69’s picture

subscribing

jfev’s picture

Does anyone know how to get this to work in 6.x? Thanks.

kvvnn’s picture

Subscribers may want to check out http://drupal.org/node/411360

bryancasler’s picture

subscribing, any update?

lhernon’s picture

subscribing

mErilainen’s picture

subscribing + giving my two cents

Nowadays when one is filling a form with a location, only the city is required and some ajax magic will find all the cities and suggest them from different countries. In my opinion this is the fastest way to fill a form with a location.

hutch’s picture

The "ajax magic" would require a table with all the city names in (and lats/lons) to fill the autocomplete dropdown. setting up the ajax callback is the easy part ;-)

mErilainen’s picture

Yeah, I don't know how difficult it will be technically, but there must be some library which can be used, like Google Maps API for coordinates. I doubt every site I have used have their own database with all the cities, countries and locations stored separately.

hutch’s picture

There may well be subscribed services available, at a price. The google maps API as far as I can see does not provide an 'as-you-type' ajax service to use with autocomplete dropdowns. What it does provide is a lat/lon coordinate on a supplied address so that a marker can be placed on the map, center map on that point, zoom in, do proximity searches etc.

mErilainen’s picture

That might be the case, it's sad if it's so. I was working on a project before where we investigated all the different cases how to discover user's location using ip, wlans, gps and such, and for most of the mobile brands you need to pay some license to enter the phone's hardware (gps, or network cell ids).

Which brings me to another improvement: with some javascript it's easy to discover user's location when using W3C's Geolocation API. Works well with Firefox and Chrome. A simple function navigator.geolocation.getCurrentPosition() will ask the user for the location, and that information can be parsed to fill the fields in Location module. Works even in the oh-so-wonderful iPhone.

hutch’s picture

Sounds like a nice project for someone familiar with mobile and gps technology ;-)

benone’s picture

+1

kndr’s picture

Please check my proposal at #1106464: Geocode via Ajax - improved UI

legolasbo’s picture

Status: Needs work » Closed (outdated)

Closing old D6 issues as D6 is end of life