/    Sign up×
Community /Pin to ProfileBookmark

Iphone navigation javascript – sql query?

Hi Guys,
I want to include the iphone gps long and lat into my website to be added to a sql query.

Gets GPS long and lat from iphone and pops it in a div:

[CODE]<html>
<head>

<script type=”text/javascript”>

function getGPS() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showGPS, gpsError);
} else {
gpsText.innerText = “No GPS Functionality.”;
}
}

function gpsError(error) {
alert(“GPS Error: “+error.code+”, “+error.message);
}

function showGPS(position) {
gpsText.innerText = “Latitude: “+position.coords.latitude+”nLongitude: “+position.coords.longitude;

// alternate
//gpsText.innerHTML = “<a href=’http://maps.google.com/maps?q=”+position.coords.latitude+”,”+position.coords.longitude+”+(Your+Location)&iwloc=A&z=17′>”+position.coords.latitude+”,”+position.coords.longitude+”</a>”;
}

</script>
</head>

<body>

<a href=# onclick=”getGPS()”>Get GPS Data</a>

<div id=gpsText></div>

</body>
</html>[/CODE]

I want this to work like a tracking system where it gets the gps long and lat from the iphone and then adds it to a sql table (id, user_id, long, lat).
I have the code to get the long and lat but how do i get the script to add them to a sql query from java?
Also how can i get the script to refresh every 15 mins to overwrite the last long and lat?
Im running PHP and javascript
Thanks
Adam

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@adamckauthorApr 07.2010 — basically to confirm...

I want to run the following from above every 15 mins and then do an SQL query similar to this:

[CODE]INSERT INTO database.location (id ,user_id ,long ,lat) VALUES (NULL , 'adam', +position.coords.longitude+', '+position.coords.latitude+');[/CODE]
Copy linkTweet thisAlerts:
@adamckauthorApr 08.2010 — Anyone?
Copy linkTweet thisAlerts:
@adamckauthorApr 08.2010 — ok so i tried this...
[CODE] <script type="text/javascript">

function getGPS() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showGPS, gpsError);
} else {
gpsText.innerText = "No GPS Functionality.";
}
}
long = position.coords.longitude;
lat = position.coords.latitude;
function gpsError(error) {
alert("GPS Error: "+error.code+", "+error.message);
}

function showGPS(position) {
gpsText.innerHTML = "<?php $long = "".$_GET['long'].""; $lat = "".$_GET['lat'].""; $sqldel = "INSERT INTO location (id ,user_id ,long ,lat) VALUES (NULL , '$user', '$long','$lat' );"; mysql_query($sqldel) or die(mysql_error()); echo "$long"; echo "$lat"; ?>";
}

</script>[/CODE]


Which runs the query and posts into the table but it wont use the variables set in the javascript.

Is it possible to transfer these variables in any way without leaving the page?

Thanks
×

Success!

Help @adamck spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...