I am trying to pass the users lattitude and longitude into the directions input on the tab the below code ads a button that requests the users location and displays it but i cant work out how to set it as a variable and echo it via php.
I did echo the word cool though.
<?php if ($geodir_map_options['enable_map_direction']) { ?>
<input type="text" id="<?php echo $map_canvas_name; ?>_fromAddress" name="from" class="textfield"
value="<?php echo cool; ?>"
onblur="if (this.value == '') {this.value = '<?php echo ENTER_LOCATION_TEXT; ?>';}"
onfocus="if (this.value == '<?php echo ENTER_LOCATION_TEXT; ?>') {this.value = '';}"/>
<input type="button" value="<?php _e('Get Directions', 'geodirectory'); ?>"
class="<?php echo $map_canvas_name; ?>_getdirection" id="directions"
onclick="calcRoute('<?php echo $map_canvas_name; ?>')"/>
<button onclick="getLocation()">Near Me</button>
<p id="demo"></p>
<script>
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
x.innerHTML = position.coords.latitude +","+ position.coords.longitude;
}
</script>
<script>
<?php if(geodir_is_page('detail')){?>
jQuery(function () {
gd_initialize_ac();
});
Any help would be great from anyone! Thankyou 🙂