Start New Discussion within our Web Development Community

Hello :D
Im 100% noob to javascript..

now, i have this script:

<script>
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
document.write(position.coords.latitude + '_' + position.coords.longitude);
});
} 
</script>

and i need to send the location data to a php script..
Is there any easy and smart way to do souch things?

The easy way will be to redirect to ?data=OUTPUT FROM GEOLOCATION FUNCTION
But how do i do that??

i have tried this, without success:

<script>
    if(navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position) {
    window.location=("http://mypage.com/?data=position.coords.latitude + '_' + position.coords.longitude");
    });
    } 
 </script>

But it just send me to a page named: http://mypage.com/?data=position.coords.latitude%20+%20'_'%20+%20position.coords.longitude

i want it to send me to: http://mypage.com/?data=55.673514_12.465726

How do i do that?? :D

Regards Lasse

window.location=("http://mypage.com/?data=position.coords.latitude + '_' + position.coords.longitude");
It's because u put it in quotation marks as a string. Change it to
window.location=("http://mypage.com/?data=" + position.coords.latitude + "_" + position.coords.longitude);
That should do it.

This question has already been answered. Start a new discussion instead.