user3407174
user3407174

Reputation:

Latitude and longitude cookies

Good afternoon,

I'm trying to save in a 2 different cookies the information of latitude and longitude. This code worked on my computer, but it's not working on my mobile devices (the cookies are empty). What can I do in order to make it work?

That's my code:

<script type="text/javascript">
function getGPS()
{
    if (navigator.geolocation)
    {  
        navigator.geolocation.getCurrentPosition(showGPS);
    }
    else
    {  
        gpsText.innerText = "No GPS Functionality.";  
    }
}
function showGPS(position)
{
    document.cookie="latitude="+position.coords.latitude;
    document.cookie="longitude="+position.coords.longitude;
}
</script>

Edit: My website is : http://www.idermo.es/index.php?option=com_content&view=article&id=123&Itemid=747

Is that well geolocalised for you?

Edit:

And that's my body tag:

<body onLoad="getGPS();">

Why is my code not entering the Javascript creation cookie? Because I have tested with a "alert("wow")" and it didn't show anything.

Thanks,

Regards,

Upvotes: 0

Views: 2973

Answers (1)

Vasiliy vvscode Vanchuk
Vasiliy vvscode Vanchuk

Reputation: 7159

Did you check if code run showGPS function ?

what about

<script type="text/javascript">
function getGPS()
{
    if (navigator.geolocation)
    {  
        navigator.geolocation.getCurrentPosition(showGPS);
    }
    else
    {  
        gpsText.innerText = "No GPS Functionality.";  
    }
}
function showGPS(position)
{
    alert('Wow!');
    document.cookie="latitude="+position.coords.latitude;
    document.cookie="longitude="+position.coords.longitude;
}
</script>

?

P.S> I have no iPhone , but my android browser has secure setting which allow/deny use cookies and navigator

Upvotes: 1

Related Questions