Currently in D8:
- Browser location centers the map on the users location, but values are not stored. It's designed as a help for manually finding your exact location by clicking the map to add a marker.

Currently still missing from D7:
- Browser location centers the map on the users location
- Marker is set
- Zoom is applied based on the accuracy level the browser returns (this differs significantly between desktop and mobile, which is pretty on spot)
- The marker can then be manually adjusted

New in D8:
- support client location capability

Comments

ChristianAdamski created an issue. See original summary.

christianadamski’s picture

Issue summary: View changes
juliencarnot’s picture

Hi Christian,

Do you envision these "missing" features as alternative settings or as a replacement for the current dev feature? It seems like there could be 2 different modes:

  • offer the user to click on the button to help centering the map around her and let her set the marker
  • get the location from the browser and set it as the marker, and allow for further adjusting

In my use case, I want to set the location by default, as soon as possible and without requiring the user to click/tap to use it (of course, the user can discard the feature by not sharing his location in the browser UI), to give her a visual indication of the accuracy of the position (a disc on the map) and allow her to call the position again (to get a better accuracy) or to set the right position (the disc disappears when the marker is moved by the user or when the marker is set from search). This seems to cover the described features pretty well.

I got this to work through this old patch, you can try it here.

Do you think these two modes could coexist through an "autolocate" or "autofill with user position" option in the form display settings for the content type? Thanks for your insight!

christianadamski’s picture

Hello Julien,

good to hear from you. This issue is just a copy of what @derjochenmeyer noticed as missing compared to D7.
I think the current super-simple mode could stay as default, but the widget settings allow for more fancy behavior.

So if you build a patch that leaves the default as is, but adds your functionality based on a widget setting, I'll be happy to commit it. Ideally, you would build this in a way to en-/disable the single features separately.

All default "No":

[ ] Set marker when client location available
[ ] Visualize accuracy estimation on map
[ ] Allow drag'n'drop of marker

That last option seems independent of the client location though, right?

Thank you,

Christian

derjochenmeyer’s picture

options sound great. every site will have its own requirements.

- center on pageload yes/no
- show center on click button yes/no
- show accuracy yes/no
- show marker yes/no
- allow readjusting the marker yes/no
- reverse geocode the marker/center and show closest address info yes/no
- autozoom depending on accuracy yes/no

EWB’s picture

Regarding the "allow readjusting the marker" feature - and as you may already know - it appears that the Geolocation OSM sub-module has this functionality in place. While realizing that the code may not be swappable, I thought it worth noting in case it helps this module's maintainers move this (awesome) module forward.

christianadamski’s picture

Hey, see #2804385: Add default center option for Geolocation Google Geocoder.

Takes care of:
- marker is set if value is present
- use client location if available
- adds new: default lat lng when no value set yet

derjochenmeyer’s picture

So we could update the description of this issue and tick off some of the missing features?

christianadamski’s picture

Issue summary: View changes
juliencarnot’s picture

StatusFileSize
new4.01 KB

I tested both modes in the latest dev version (centering and setting value) and found 2 issues with the latter mode:

  • the marker is set, but the hidden field values are left untouched, which is really counterintuitive, given that setting the marker usually sets/update the value in this widget. Fixed that by setting Drupal.geolocation.geocoderWidget.setHiddenInputFields with the position.coords...
  • The locate button remains in the centering only mode even if the setting value mode is chose. Setting the marker and then clicking on locate button has no effect on the marker. Edge use case I guess, but still can happen...

The following patch also include enhancements for the setting value mode: if using HTML5 location to set the marker, a circle representing the accuracy of HTML5 location is drawn and the map viewport is bound to it, so that the user can tell if the position can be trusted and can adjust it easily. The circle disappears when clearing the geolocation values or when moving the marker manually.

I think this on top of the latest dev version would solve the remaining points listed in the issue (if backported to D7 version).

juliencarnot’s picture

Status: Active » Needs review
christianadamski’s picture

Hey, thanks for your Code. Only on my phone right now, not really able to review.

On first look though: you added the circle magic to geolocation-geocoder.js?

The idea there is to separate the geocoder JS from Google. You know, so other people can use this module without Google.

Can you move that code to the Google specific one?

juliencarnot’s picture

Thanks for your quick feedback!

The "circle magic" is in geolocation-geocoder to apply on locate button click and in geolocation-widget-googlegeocoder to apply on load. I'm sure there's a better way to avoid code duplication and I understand the logic behind separating Google from the geocoder JS and I'm looking forward to alternative maps, but it looks like geolocation-geocoder is still full of Google Maps API features. I guess geolocation-geocoder should call a getAccuracy function on locate button click, the function being declared in geolocation-widget-googlegeocoder for google maps and/or in another future js with the same feature for mapbox or leaflet, is that it?

I guess I should seriously learn to code for that, I gave it a run through my usual observation/trial/error process and couldn't get it to work, really sorry about that!

dharam.sharma1991’s picture

Hi Christian,
When we can expect a release with these new features. I am also looking for the same kind of functionality, where marker location should be captured automatically and user allow to change it.
Thanks

juliencarnot’s picture

StatusFileSize
new2.13 KB

Hey Christian,

I realized that one of your recent commits had "cleaned" geolocation-geocoder.js from Google Maps references, so it was much easier for me to put the "circle magic" in a cleaner patch. Thanks for the help on that!

I've tested it on the latest dev with different settings and use cases, and it works well for me.

christianadamski’s picture

StatusFileSize
new4.09 KB

Hey @juliencarnot,

I took your patch and reworked it a bit. I generalized it into a function not tied to the widget. It also draws the circle and then fades it away 2,5s. I think its fancy. That's why I also added it to CommonMap display.

  • juliencarnot authored 7f427fd on 8.x-1.x
    Issue #2777753 by juliencarnot: Missing D7 functionality in Geocoder D8...
christianadamski’s picture

@juliencarnot I missed that nice little circle zoom trick. Added.

I assume that we have surpassed D7 functionality now and will close this issue.

If I missed something, reopen it or just open a new ticket.

christianadamski’s picture

Status: Needs review » Fixed
juliencarnot’s picture

Status: Fixed » Needs review

Thanks Christian, sounds good, especially with the zoom trick ;-) !

A few remarks after testing, with "Will use client location automatically by default" and "Will set client location marker automatically by default" set on my widget:

  • It seems that these automatic settings are not working anymore: I get the centering/zooming on map load, but the marker is not set as it was a few commits ago. When using the locate button, it is set.
  • I occasionally got this error in Firefox's console: TypeError: Drupal.geolocation.drawAccuracyIndicator is not a function geolocation-widget-googlegeocoder.js:172:15 , but I can't seem to reproduce it.
christianadamski’s picture

Status: Needs review » Fixed

Hey @juliencarnot,

It seems that these automatic settings are not working anymore: I get the centering/zooming on map load, but the marker is not set as it was a few commits ago. When using the locate button, it is set.

It's not a bug, it's a feature. The behavior before was wrong. Default values are set in the fields settings. The lat/lng in the widget settings only influence the map, as the description there also states.

I occasionally got this error in Firefox's console: TypeError: Drupal.geolocation.drawAccuracyIndicator is not a function geolocation-widget-googlegeocoder.js:172:15 , but I can't seem to reproduce it.

I hope it's a caching issue. If it happens again, re-open.

juliencarnot’s picture

Humm, sorry if I haven't been clear. I agree about the change for default value from widget to field and the default value not setting the marker/inputs anymore, but we have 2 modes for the setting, as described in #3 and controlled by these settings in t:

  • Automatically use client location, when no value is set
  • Automatically set marker to client location as well

I have both settings on, and the resulting behaviour is what I expect from the first option alone. In fact, I can't see a difference of behaviour whether "Automatically set marker to client location as well" is checked or not. Am I missing something?

Can't see the js error so it was probably some cache issue.

christianadamski’s picture

Ah, good find! The code there was correctly triggering and correctly setting the initial location.

However, the whole client location stuff is executed much later and the map was already loaded at that point.

Asynchronous Javascript and stuff.

I'm pushing the fix together with #2829159: Compact and descriptive UI for Google Maps geocoder widget and leave this closed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.