0

Iphone/web サイト アプリ (instamapper) から GPS 座標を取得し、それを自分の web サイト ページに追加する php/javascript コードがあります。(これまでのところ、他の人々のコード例のスニペットを使用しています)ポップアップを小数点座標の表示から適切な緯度/経度に変更したいのですが、うまくいきません。皆さんが与えることができる助けや指針は素晴らしいでしょう。私のコードは以下です。

ここにあります 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&amp;v=2&amp;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>');

?>
4

1 に答える 1

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
于 2012-05-04T18:01:47.180 に答える