我正在尝试通过 php 从 android 设备向 mysql 发送地理位置数据。由于某种原因,它不起作用。它不会出现在 mySQL 数据库中。难道我做错了什么?
AS3
var myLat;
var myLong;
if (Geolocation.isSupported){
var my_geo:Geolocation = new Geolocation();
my_geo.addEventListener(GeolocationEvent.UPDATE, onGeoUpdate);
my_geo.setRequestedUpdateInterval(100);
}
function onGeoUpdate(event:GeolocationEvent):void {
myLat = event.latitude;
myLong = event.longitude;
test1.text = myLat;
test2.text = myLong;
}
// Send Geolocation
function sendGps():void {
var variables:URLVariables = new URLVariables();
var varSend:URLRequest = new URLRequest("http://www.mypage.com/handler.php");
varSend.method = URLRequestMethod.POST;
varSend.data = variables;
var varLoader:URLLoader = new URLLoader;
varLoader.dataFormat = URLLoaderDataFormat.TEXT;
variables.myrequest = "write_gps";
variables.username = userName;
variables.lati = myLat;
variables.longi = myLong;
varLoader.load(varSend);
}
var myTimer:Timer = new Timer(1000);
myTimer.addEventListener(TimerEvent.TIMER, runItAll);
myTimer.start();
function runItAll(event:TimerEvent):void {
sendGps();
}
PHP
if (isset($_POST['myrequest']) && $_POST['myrequest'] == "write_gps") {
$username = $_POST['username'];
$latitude = $_POST['lati'];
$longitude = $_POST['longi'];
require_once "connect_to_mysql.php";
$update_sql = mysql_query("UPDATE current SET longitude='$longitude', latitude='$latitude' WHERE username='$username'");
mysql_close();
};