Jump to content

Recommended Posts

I have a link <a href="http://www.sowx.ca/eccast/eccast.php"> as well as a javascript function that gets latitude and longitude seen below. What I need to do is take the latitude longitude and have it set the link as <a href="http://www.sowx.ca/eccast/eccast.php?lat=+lat&lon=+lon> fron the javascript function. I was able to do this by setting the href with an id and changing the . href attribute with the id however It did not work in Firefox. I imagine I have to use onclick() or something along those lines. If someone could help me out with this that would be awesome.

 

Thanks, Dave

				<script type="text/javascript">

if (navigator.geolocation) {
  navigator.geolocation.getCurrentPosition(successFunction, errorFunction);
  } else {
  alert('Geolocation is required for this page,');
}

function successFunction(position) {
  var lat = position.coords.latitude;
  var lon = position.coords.longitude;
  
}

function errorFunction(position) {
  alert('Error!');
}
</script>
Edited by davefootball123
Link to comment
https://forums.phpfreaks.com/topic/275248-need-help-setting/
Share on other sites

So what was the code you tried? I assume it went inside successFunction()?

Yes it did for example I had the code seen below and my <a href had an id of "loc", worked ok in chrome and IE...just not firefox. 

document.getElementById("loc").href='eccast.php?lat='+lat+'&lon='+lon; 
Edited by davefootball123
Link to comment
https://forums.phpfreaks.com/topic/275248-need-help-setting/#findComment-1416596
Share on other sites

 

window.onerror = function(message, url, lineNumber) {  
  alert(message + " | " + lineNumber + " | " + url);
  return true;
};  

 

Add the code above and / or look at your console. (Run it again afterwards.)

Thanks for your response.

Surprisingly it doesn't return an error. I notice this. It works as it should in Chrome and in Internet Explorer, however I have to load the page and then do 1 refresh for it to work in Firefox. Odd. Any thoughts?

 

Full code is posted below, minus the code you gave me above. 

 

				<script type="text/javascript">

if (navigator.geolocation) {
  navigator.geolocation.getCurrentPosition(successFunction, errorFunction);
  } else {
  alert('Geolocation is required for this page,');
}

function successFunction(position) {
  var lat = position.coords.latitude;
  var lon = position.coords.longitude;
  
 document.getElementById("loc").href='http://www.sowx.ca/eccast/eccast.php?lat='+lat+'&lon='+lon; 
}

function errorFunction(position) {
  alert('Error!');
}
</script>
<ul>
   <li class="current"><a href='http://www.sowx.ca'><span class="current">Warnings</span></a></li>
   <li><a href="http://www.sowx.ca/eccast/eccast.php" id="loc"><span>Local</span></a></li>
</ul>

Edited by davefootball123
Link to comment
https://forums.phpfreaks.com/topic/275248-need-help-setting/#findComment-1416629
Share on other sites

Works fine for my firefox. Although it does annoyingly ask for permission every time.

I see, chrome only asks once and you're set. Same with IE. Do you have any recommendations on how I could fix this issue? Any other geolocation api's I should look into?

Link to comment
https://forums.phpfreaks.com/topic/275248-need-help-setting/#findComment-1416636
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.