Please help - Can't get this to work

Hi

I need to run this HTML code in a php app,
or
Call this html and get the var values (results). see - showLocation(position)
Please can someone help.

HTML Code

<!DOCTYPE html>
<html lang=“en-US”>
<head>
<title>Visitor Location using HTML5 and PHP</title>
<script src=“https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js”></script>
<script>
var options = { enableHighAccuracy: true, timeout: 2000, maximumAge: 0};
$(document).ready(function(){
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showLocation, errorHandler, options);
} else {
$(’#location’).html(‘Geolocation is not supported by this browser.’);
}
});

function showLocation(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
var accuracy = position.coords.accuracy;
var heading = position.heading;
var speed = position.speed;
}

function errorHandler(err) {

put that code in a blank application, inside the onExecute event. ?> HTML CODE <?php

Sorted, just for the life of me am battling to call a php app, pass the gps info, and return, so it can continue tracking.
I have the below, but when it calls the php app ([SIZE=12px]agenttrack.php)[/SIZE], the [SIZE=12px]agenttrack.php[/SIZE] does it job then seems to freeze the main app. Been battling all day on this. Can you advise?

[SIZE=12px]var watchID;[/SIZE]
[SIZE=12px]var geoLoc;[/SIZE]
[SIZE=12px]getLocationUpdate();[/SIZE]

[SIZE=12px]function showLocation(position) {[/SIZE]
[SIZE=12px]var latitude = position.coords.latitude;[/SIZE]
[SIZE=12px]var longitude = position.coords.longitude;[/SIZE]
[SIZE=12px]var accuracy = position.coords.accuracy;[/SIZE]
[SIZE=12px]var heading = position.heading;[/SIZE]
[SIZE=12px]var speed = position.speed;[/SIZE]
[SIZE=12px]alert("Latitude : " + latitude + " Longitude: " + longitude);[/SIZE]
[SIZE=12px]$.ajax({[/SIZE]
[SIZE=12px]type:‘POST’,[/SIZE]
[SIZE=12px]url:'https://secure.XXXXXX.com/agenttrack/agenttrack.php?latX=’+latitude+’&lngY=’+longitude+’&accuracy=’+accuracy+’&heading=’+heading+’&speed=’+speed;[/SIZE]
[SIZE=12px]});[/SIZE]

[SIZE=12px]}[/SIZE]

[SIZE=12px]function errorHandler(err) {[/SIZE]
[SIZE=12px]if(err.code == 1) {[/SIZE]
[SIZE=12px]alert(“Error: Access is denied!”);[/SIZE]
[SIZE=12px]}[/SIZE]

[SIZE=12px]else if( err.code == 2) {[/SIZE]
[SIZE=12px]alert(“Error: Position is unavailable!”);[/SIZE]
[SIZE=12px]}[/SIZE]
[SIZE=12px]}[/SIZE]

[SIZE=12px]function getLocationUpdate(){[/SIZE]
[SIZE=12px]if(navigator.geolocation){[/SIZE]
[SIZE=12px]// timeout at 60000 milliseconds (60 seconds)[/SIZE]
[SIZE=12px]var options = {timeout:60000};[/SIZE]
[SIZE=12px]geoLoc = navigator.geolocation;[/SIZE]
[SIZE=12px]watchID = geoLoc.watchPosition(showLocation, errorHandler, options);[/SIZE]
[SIZE=12px]}[/SIZE]

[SIZE=12px]else{[/SIZE]
[SIZE=12px]alert(“Sorry, browser does not support geolocation!”);[/SIZE]
[SIZE=12px]}[/SIZE]
[SIZE=12px]} [/SIZE]

Oops forgot to mention this. The main app is a Control app, and I placed the code in the app Control -> JavaScript onLoad