Reply To: Geolocation?

#1688

Kevin Heath
Buyer
Post count: 33

Change the script in the header to



<?php global $goe_locate; if($goe_locate){echo $goe_locate;} ?>
<script type="text/javascript">
function showLocation(position) {
  var latitude = position.coords.latitude;
  var longitude = position.coords.longitude;
  var add = latitude+','+longitude;
  document.getElementById('detail_page_map_canvas_fromAddress').value = add;
  document.getElementById('snear').value = add;
}

function errorHandler(err) {
  if(err.code == 1) {
    alert("Error: Access is denied!");
  }else if( err.code == 2) {
    alert("Error: Position is unavailable!");
  }
}
function getLocation(){

   if(navigator.geolocation){
      // timeout at 60000 milliseconds (60 seconds)
      var options = {timeout:60000};
      navigator.geolocation.getCurrentPosition(showLocation, 
                                               errorHandler,
                                               options);
   }else{
      alert("Sorry, browser does not support geolocation!");
   }
}
</script>

In the listing-filter-form.php file immediately before you added the new input form add



  <input type="hidden" id="detail_page_map_canvas_fromAddress">

In geodirectory-functions > map-functions > map_template_tags.php

at around line 131 just before the button input add



			 <input type="button" class="geo" onclick="getLocation();">

If you want to can add a value to the input in the same way as you did with the search geo-locate.

Kevin

20% Discount Offer
Hurry! Get your 20% discount before it expires. Get 20% Discount