Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7953433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:09:31+00:00 2026-06-04T03:09:31+00:00

I’m trying to write a application that sends user’s geolocation to MYSQL database every

  • 0

I’m trying to write a application that sends user’s geolocation to MYSQL database every minute or so. This is the code I have right now, but it’s not working. How do i need to change this to make it work?

JS:

<!DOCTYPE html>
<html>
<head>
<script src="js/jquery.js"></script>
</head>

<body>
<script>
setInterval ( "onPositionUpdate()", 10000 );
function onPositionUpdate(position)
            {
                var lat = position.coords.latitude;
                var lng = position.coords.longitude;
                jQuery.ajax({ type: "POST", 
                    url:  "myURL/location.php", 
                    data: 'x='+lat+ '&y='+lng , 
                    cache: false, 
                        });
                        }

            if(navigator.geolocation)
               navigator.geolocation.watchPosition(onPositionUpdate);
            else
                alert("navigator.geolocation is not available");



</script>
</body>
</html>

and PHP:

<?php
  include 'config.php';

  // database connection
  $conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);

  // new data

  $x = @$_POST['x'];
  $y = @$_POST['y'];
  // query
  $sql = "update locations set x=?, y=? where username = asd";
  $q = $conn->prepare($sql);
  $q->execute(array($x), ($y));
?>

And I suppose this is not the right way to send multiple variables, is it?. Firebug’s console shows me

 missing } after property list
[Break On This Error]   

data: 'x='+lon+'&y='+lat;

When I use only one value, it POSTs that variable to server only once and after that console gives:

position is undefined
[Break On This Error]   

var lat = position.coords.latitude;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T03:09:32+00:00Added an answer on June 4, 2026 at 3:09 am

    You need to do something like:

    var currPosition;
    navigator.geolocation.getCurrentPosition(function(position) {
        updatePosition(position);
        setInterval(function(){
            var lat = currPosition.coords.latitude;
            var lng = currPosition.coords.longitude;
            jQuery.ajax({
                type: "POST", 
                url:  "myURL/location.php", 
                data: 'x='+lat+'&y='+lng, 
                cache: false
            });
        }, 1000);
    }, errorCallback); 
    
    var watchID = navigator.geolocation.watchPosition(function(position) {
        updatePosition(position);
    });
    
    function updatePosition( position ){
        currPosition = position;
    }
    
    function errorCallback(error) {
        var msg = "Can't get your location. Error = ";
        if (error.code == 1)
            msg += "PERMISSION_DENIED";
        else if (error.code == 2)
            msg += "POSITION_UNAVAILABLE";
        else if (error.code == 3)
            msg += "TIMEOUT";
        msg += ", msg = "+error.message;
    
        alert(msg);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm trying to create an if statement in PHP that prevents a single post
I have a reasonable size flat file database of text documents mostly saved in
I am trying to loop through a bunch of documents I have to put
I'm working with an upstream system that sometimes sends me text destined for HTML/XML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.