I'm using the combinaison of this modules :

I need to approximate the location of user's markers on the map for privacy reason.

For exemple if somebody live at 123 addressstreet 10000 Washington I want the marker on leaflet map to point a random location in the area of this address and not the real geocoded location.

What's the best way to do that ?

  • Please expand your question to (a) incude links to these modules and (b) add more details about that "approximate" (what exactly you mean, and maybe add a sample or something). Mar 9, 2017 at 20:20
  • Done, hope to be more clear.
    – Aporie
    Mar 10, 2017 at 7:22

1 Answer 1


So, there's probably several ways to do this and your approach will depend on exactly what your needs are for this app.

If you need to preserve the geofield data accurately in the db, but you just want to change the display, you'd need to write a script to modify the Leaflet JS create.point function. This is complicated because you'll have to consider things like the visual context of what you're mapping (i.e. if there's only one house in an area, then even abstracting the location won't really accomplish what you want). Also, your changes will get wiped if your not careful upgrading modules potentially exposing the addresses your trying to hide (depending on how sensitive your data is, this may expose it as well, because someone might be able to dig through the JS and extract the original coordinates). This is also complicated, because simply randomizing the lat-lon data will produce really wonky map results (here's an alternate approach to randomizing user data. I would think that a good approach would be to choose a distance offset, and then randomly apply it to either the lat or lon value. This will keep your point close to where it should be, but it will be offset on either the X or the Y axis to the point where it shouldn't be on the exact location. You could also take the approach where you mis-match the real locations of the users to other users.

If you don't need to store the Lat-Lon accurately, you could write a custom module to hook into the geofield_compute_location function and apply your offset there. This will keep your addresses intact and then apply a similar function to the lat-lon values returned by whichever service is providing your geocoding. This will give you obscured location data to pull into your view.

There's also probably a way of modifying the geocoding request to only provide city-level accuracy, but this is getting over my head.

Hope this helps.

  • Yes, it helps but it's not a final solution. I forbid to zoom too much which is obviously not the best solution but do the trick, at least until I don't have too much user registered. I think changing parameters in the module files to put offset will be the best solution, but I tried to find the "style: margin: offset" and can't figured it out.
    – Aporie
    Mar 10, 2017 at 12:55
  • Unfortunately, I'm not intimately familiar with leaflet, but the styling for markers should be in the js files somewhere
    – nizz0k
    Mar 10, 2017 at 18:37
  • Yeah tried to find it and no way. If I figured it out will post it here.
    – Aporie
    Mar 10, 2017 at 19:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.