Hi Support,
I have been smashing my head against a brick wall trying to pull the users geolocation into AwareIM for further processing.
Basically, I call a php page using URL_CONTENTS and then parse the content to extract the latitude and longitude so that I can continue on with my process. If I run the php page in a browser it works perfectly but when I use the url_contents it does not process the page properly.
If you would take a quick look at my code below and point out any glaring errors or let me know why the php page is not running via url_contents I would be in your debt:
PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Find Me</title>
</head>
<body>
<form method="post" action="GeoLocation5.php#done">
<input type="hidden" size="100" id="lat" name="latit" >
<input type="hidden" size="100" id="lon" name="long" >
</form>
<script>
if (location.hash == '') setTimeout('SubForm()', 1000); // delay 3 seconds
function SubForm() {
document.forms[0].submit();
}
</script>
<?php
//Retrieve string from post submission
$lati = $_POST['latit'];
$long = $_POST['long'];
echo "latbegin$lati";
echo "latend";
echo "lonbegin$long";
echo "latend";
?>
</body>
<script type="text/javascript">
function findmeifyoucan()
{
if( navigator.geolocation )
{
navigator.geolocation.getCurrentPosition( win, fail );
}
else
{
alert("Sorry, your browser does not support this functionality");
}
}
function win(youare)
{
var longi;
longi=document.value = youare.coords.longitude;
var lati;
lati=document.value = youare.coords.latitude;
document.getElementById("lat").value = youare.coords.latitude;
document.getElementById("lon").value = youare.coords.longitude;
}
function fail()
{
//didntwork
}
</script>
<script type="text/javascript">
findmeifyoucan();
</script>
You can test this code by visiting: http://www.workxid.ca/GeoLocation5.php
However when I access the page via url_contents, the following code is returned:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Find Me</title></head> <body><form method="post" action="GeoLocation5.php#done"> <input type="hidden" size="100" id="lat" name="latit" > <input type="hidden" size="100" id="lon" name="long" ></form><script> if (location.hash == '') setTimeout('SubForm()', 1000); // delay 3 secondsfunction SubForm() {document.forms[0].submit();} </script> latbeginlatendlonbeginlatend</body><script type="text/javascript">function findmeifyoucan(){ if( navigator.geolocation ) { navigator.geolocation.getCurrentPosition( win, fail ); } else { alert("Sorry, your browser does not support this functionality"); }} function win(youare){var longi;longi=document.value = youare.coords.longitude;var lati;lati=document.value = youare.coords.latitude;document.getElementById("lat").value = youare.coords.latitude;document.getElementById("lon").value = youare.coords.longitude;}function fail(){ //didntwork}</script> <script type="text/javascript">findmeifyoucan();</script>
It is as if it is returning the raw html code without having run the javascript on the page. I have tried numerous methods to get it to work but none of my approaches actually run the script as it does when you call the page through a browser.
Any ideas or suggestions?
Thanks!
Pete