我有一个php / javascript代码,它从Iphone /网站应用程序(instamapper)获取GPS坐标并将其添加到我的网站页面。 (到目前为止,使用其他人代码示例的代码片段)我想将弹出窗口从显示小数点坐标更改为正确的Lat / Long但是无法完成它。你们给予的任何帮助或指示都会很棒。我的代码如下。
在此处找到http://www.morvargh-sailing.co.uk/tracker/test2.php
<?php
$key = "16194603621692259587";
$fichier = "http://www.instamapper.com/api?action=getPositions&key=".$key."&num=1";
$fp=@fopen($fichier,"r");
$texte = "";
if($fp)
{
while(!feof($fp))
{
$texte .= fgets($fp,1024);
}
}
$donnees = explode(',',$texte);
/*
0 : first line plus device number
1 : Device label
2. Position timestamp in UTC (number of seconds since January 1, 1970)
3. Latitude
4. Longitude
5. Altitude in meters
6. Speed in meters / second
7. Heading in degrees
*/
date_default_timezone_set('GMT');
$name = $donnees[1];
$date = date('H:i:s d-m-Y e', $donnees[2]);
$lat = $donnees[3];
$longitude = $donnees[4];
$altitude = $donnees[5];
$speed = $donnees[6];
$heading = $donnees[7];
echo('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Where am I</title>
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAA_GqVjhr7wgurGjr_zR-wJxSbxjqNwl0XTkuBKGwUYonF3JCDWBRyXrxgjwLgrUjcet0gLjyGZOGwCA" type="text/javascript"></script>
<style type="text/css">
v\:* {behavior:url(#default#VML);}
html, body {width: 100%; height: 350px}
body, form, p {margin: 0; padding: 0; text-align:center; font-family:"lucida grande","trebuchet ms",sans-serif; font-size:12px;}
a:link, a:visited, a:hover {color: #369; background:transparent; text-decoration: none;}
#instamapper {position:absolute; left:80px; bottom:10px;}
#instamapper p {text-align:right;}
</style>
</head>
<body onLoad="showAddress(\''.$lat.', '.$longitude.'\'); return false" onunload="GUnload()">
<div id="map" style="width: 100%; height: 100%;"></div>
<div id="instamapper">
<p>
GPS tracking powered by <a href="http://www.instamapper.com/">InstaMapper</a>
<p>
<div>
<script type="text/javascript">
//<![CDATA[
var momento = "'.$date.'";
var altitud = "'.$altitude.'" + "m";
var velocidad = "'.$speed.'" + " Km/h";
var longitude = "'.$longitude.'";
var latitude = "'.$lat.'";
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
var geocoder = new GClientGeocoder();
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
function showAddress(address) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
alert("\"" + address + "\" no encontrado");
} else {
map.setCenter(point, 12);
var marker = new GMarker(point);
var info = "<b>Last known location:</b><p>Time: " + momento + "<br>Latitude: " + latitude + "<br>Longitude: " + longitude + "<br>Heading: " + '.$heading.' +"º";
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml(info);
});
map.addOverlay(marker);
marker.openInfoWindowHtml(info);
}
}
);
}
}
//]]>
</script>
</body>
</html>');
?>
答案 0 :(得分:2)
尝试此功能:http://jsfiddle.net/eAUJr/1/
function format(newLat, newLng) {
if (newLat < 0) {
newLat = myround(Math.abs(newLat)) + "S";
} else {
newLat = myround(newLat) + "N";
}
if (newLng < 0) {
newLng = myround(Math.abs(newLng)) + "W";
} else {
newLng = myround(newLng) + "E";
}
return[newLat, newLng];
}
function myround(val) {
deg = parseInt(val);
val -= deg;
val *= 60;
min = parseInt(val);
val -= min;
val *= 60;
sec = parseInt(val);
remainder = val - sec;
if(remainder >= 0.5) {
sec += 1;
}
return deg + "°" + min + "'" + sec + '"';
}
document.write(format(-0.000277778, 20.292))
// output: 0°0'1"S,20°17'31"E