3 posts by 2 authors in: Forums > Off Topic / Other
Last Post: September 18, 2017   (RSS)

By Zicky - September 18, 2017

Has anyone tried using HTML5 Geo Location to power Geocoder's Proximity Search?

Here's a bit of example code of geolocation:


<!doctype html>
<meta charset="UTF-8">
<title>Geolocation Example</title>

<p>Sourced: <a href="https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/Using_geolocation">https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/Using_geolocation</a></p><br><br>

<p><button onclick="geoFindMe()">Show my location</button></p>
<div id="out"></div>

<script type="text/javascript">
function geoFindMe() {
  var output = document.getElementById("out");

  if (!navigator.geolocation){
    output.innerHTML = "<p>Geolocation is not supported by your browser</p>";

  function success(position) {
    var latitude  = position.coords.latitude;
    var longitude = position.coords.longitude;

    output.innerHTML = '<p>Latitude is ' + latitude + '° <br>Longitude is ' + longitude + '°</p>';

    var img = new Image();
    img.src = "https://maps.googleapis.com/maps/api/staticmap?center=" + latitude + "," + longitude + "&zoom=13&size=300x300&sensor=false";


  function error() {
    output.innerHTML = "Unable to retrieve your location";

  output.innerHTML = "<p>Locating…</p>";

  navigator.geolocation.getCurrentPosition(success, error);


Wondering if this can be accomplished.


By Dave - September 18, 2017

Hi Zicky, 

For any of the GeoCoder search forms, such as the example form: 

  • Plugins > GeoCoder > Example Code > Proximity search with results sorted by distance

You can specify the "fromAddress" as Latitude, Longitude with a comma in the middle, eg: 49.282729,-123.120738

So you could make a button that requested the users current location from the navigator.geolocation browser API and then set the value of the fromAddress to their Lat,Lng coordinates.

Hope that helps!

Dave Edis - Senior Developer