var sent='selectmark.php?user_id='+ user +'&lon='+lonlatGCS1.lon+'&lat='+lonlatGCS1.lat+jQuery.now();
$(function(){
$.getJSON(sent,function(data){
alert("Hello");
});
});
Code (get.php)
<!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>Untitled Document</title>
</head>
<body>
<?
/*$lonsent=$_GET['lon'];
$latsent=$_GET['lat'];
$user_id=$_GET['user_id'];*/
$lonsent=103.35113525391;
$latsent=14.923554399044;
$user_id=5;
include "connect-db.php";
$query=mysql_query("select * from mark where user_id='$user_id'")or die("error1".mysql_error());
$num=mysql_num_rows($query);
for($i=0;$i<$num;$i++)
{
$result=mysql_fetch_array($query);
$id=$result['id'];
$lon=$result['lon'];
$lat=$result['lat'];
$newlon=abs($lon-$lonsent);
$newlat=abs($lat-$latsent);
$powlon=pow($newlon,2);
$powlat=pow($newlat,2);
$min=sqrt($powlat+$powlon);
$update=mysql_query("update mark set min='$min' where id='$id'")or die("error2".mysql_error());
}
$select=mysql_query("select * from mark where min=(select min(min) from mark where user_id='$user_id')")or die("error3".mysql_error());
$re=mysql_fetch_array($select,MYSQL_ASSOC);
$json_data[]=array(
"id"=>$re['id'],
"detail"=>$re['detail'],
);
$json= json_encode($json_data);
echo $json;
?>
</body>
</html>
if ( $bInsertLastLogin == true ) {
//---------------------- update count_login + 1
mysql_query("UPDATE users SET count_login = count_login + 1 WHERE id = '$g_ownerid' ") or die('Query failed: ' . mysql_error());
//---------------------- insert users_log
$query = "INSERT INTO users_log(dt_log, username, doing, value, ip ) VALUES (now(), '$g_ownerusername', 'login_web', 'success', '$ip_post')";
mysql_query($query) or die('Query failed: ' . mysql_error());
}
//-----showmark-----
$sql1="select * from mark where user_id='$g_ownerid'";
$query1=mysql_query($sql1)or die ("can not select".mysql_error());
$num1=mysql_num_rows($query1);
mysql_free_result($result);
mysql_close($con);
?>
<script src="http://openlayers.org/api/OpenLayers.js" type="text/javascript"></script>
<link rel="stylesheet" href="http://openlayers.org/dev/theme/default/style.css" type="text/css">
<link rel="stylesheet" href="http://openlayers.org/dev/examples/style.css" type="text/css">
<script type="text/javascript">
var a;
var g_lonStart=<?=$lon?>;
var g_latStart =<?=$lat?>;
var g_zoomStart = 14;
var g_map, g_markers, g_layer_trace , g_point_car , g_line_car, g_marker_get;
var g_cookie_fbid = "";
var g_line_oldpoint; // keep last position for draw line
var gmap = new OpenLayers.Layer.Google("Google Streets",{numZoomLevels: 22});
var gsat = new OpenLayers.Layer.Google("Google Satellite",{type: G_SATELLITE_MAP, numZoomLevels: 22});
var ghyb = new OpenLayers.Layer.Google("Google Hybrid",{type: G_HYBRID_MAP, numZoomLevels: 22});
g_layer_trace = new OpenLayers.Layer.Vector("เส้นทางเดินรถ");
g_markers = new OpenLayers.Layer.Markers("รถ");
g_map.addLayers([gmap, gsat, ghyb, g_layer_trace, g_markers]);
g_map.setCenter(new OpenLayers.LonLat(g_lonStart, g_latStart), g_zoomStart);
g_map.addControl(new OpenLayers.Control.PanZoomBar());
g_map.addControl(new OpenLayers.Control.LayerSwitcher());
g_map.addControl(new OpenLayers.Control.Permalink());
g_map.addControl(new OpenLayers.Control.MousePosition());
g_map.addControl(new OpenLayers.Control.KeyboardDefaults());
g_map.events.register("mouseup", g_map, function(e) {
var pixel = this.events.getMousePosition(e);
var lonlat = g_map.getLonLatFromPixel(pixel);
lonlatGCS = lonlat.transform(new OpenLayers.Projection("EPSG:31258"),new OpenLayers.Projection("EPSG:4326"));
OpenLayers.Util.getElement("coords").innerHTML = lonlatGCS;
document.getElementById("lon").value = lonlatGCS.lon;
document.getElementById("lat").value = lonlatGCS.lat;
});
var markers = new OpenLayers.Layer.Markers( "บริษัท สุรินทร์อินสไปร์ จำกัด" );
g_map.addLayer(markers);
var size = new OpenLayers.Size(21,25);
var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
var icon = new OpenLayers.Icon('./images/tata.png',size,offset);
markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(103.47423277795,14.889803999976),icon));
markers.id = "บริษัท สุรินทร์อินสไปร์ จำกัด ตัวแทนจำหน่ายรถยนต์ ทาทา มอเตอร์ส จ.สุรินทร์";
markers.events.register("mousedown", markers, function() {
alert(this.id);
});
var markers1 = new OpenLayers.Layer.Markers( "Markers" );
g_map.addLayer(markers1);
var markdetail = new OpenLayers.Layer.Markers( "รายละเอียด" );
g_map.addLayer(markdetail);
markdetail.setVisibility(false);
?>
var lon=<?=$lon?>;
var lat=<?=$lat?>;
var size = new OpenLayers.Size(21,25);
var size1 = new OpenLayers.Size(100,50);
var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
var icon = new OpenLayers.Icon('./images/talk.png',size,offset);
var icon1 = new OpenLayers.Icon('./images/mark/'+mark_id+'.png',size1,offset);
markdetail.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(lon,lat),icon1));
markers1.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(lon,lat),icon));
<?
}
?>
g_map.events.register("mousemove", g_map, function(e1) {
var pixel1 = this.events.getMousePosition(e1);
var lonlat1 = g_map.getLonLatFromPixel(pixel1);
lonlatGCS1 = lonlat1.transform(new OpenLayers.Projection("EPSG:31258"),new OpenLayers.Projection("EPSG:4326"));
OpenLayers.Util.getElement("coords1").innerHTML = lonlatGCS1;
document.getElementById("lon1").value = lonlatGCS1.lon;
document.getElementById("lat1").value = lonlatGCS1.lat;
});
markers1.events.register("mousedown", markers1, function() {
var user=<?=$g_ownerid?>;
var sent='selectmark.php?user_id='+ user +'&lon='+lonlatGCS1.lon+'&lat='+lonlatGCS1.lat+jQuery.now();
$(function(){
$.getJSON(sent,function(data){
alert("Hello");
});
});
if ( g_marker_get[intCarID] != null ) g_markers.removeMarker(g_marker_get[intCarID]);
var lonlat_get = new OpenLayers.LonLat(lon_last , lat_last);
if(document.form1.hdshow.value=='plat'){
var pic_get = './images/car_plat/' + car_platnumber +'.png';
var sz = new OpenLayers.Size(65, 40);
}
else{
var pic_get = './images/car_picture/' + car_picture_last;
var sz = new OpenLayers.Size(34, 25);
}
var calculateOffset = function(size) { return new OpenLayers.Pixel(-(size.w/2), -size.h); };
var icon_get = new OpenLayers.Icon(pic_get, sz, null, calculateOffset);
g_marker_get[intCarID] = new OpenLayers.Marker(lonlat_get, icon_get);
g_markers.addMarker(g_marker_get[intCarID]);
//check(intCarID);
if ( $('input[value=followcar'+intCarID+']').is(':checked') ) g_map.setCenter(new OpenLayers.LonLat(lon_last, lat_last));
}
catch(err) {
//alert("not found"+ err);
}
});
}
function delMarkers(intCarID) {
}
function refreshMarkers(intCarID) {
delMarkers(intCarID);
addMarkers(intCarID);
}
markers1.events.register("mousedown", markers1, function() {
var user=<?=$g_ownerid?>;
var sent='selectmark.php?user_id='+ user +'&lon='+lonlatGCS1.lon+'&lat='+lonlatGCS1.lat+jQuery.now();
$(function(){
$.getJSON(sent,function(data){
alert("Hello");
});
});