0

「center: new google.maps.LatLng」このコマンドを使用する場合、通常はこの形式を使用します(22.621177,120.298311)

でも私のソースは7 05.16' N, 171 21.88' E

誰かが次に何をすべきか知っていますか?

function load(User_Id) {
  var map = new google.maps.Map(document.getElementById("map_canvas"), {
    center: new google.maps.LatLng(22.601914,120.283186),
    zoom: 13,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  });

var infoWindow = new google.maps.InfoWindow;
var geocoder = new google.maps.Geocoder();


  downloadUrl("db_2_xml.php?id="+User_Id, function(data) {
    var xml = data.responseXML;
    var markers = xml.documentElement.getElementsByTagName("markers");

    for (var i = 0; i < markers.length; i++) {
      var vessel = markers[i].getAttribute("vessel");


      var geocoder = new google.maps.Geocoder(
        geocoder.geocode(markers[i].getAttribute("GPS")));

  var speed = markers[i].getAttribute("speed");


      var icon = customIcons[type] || {};
      var marker = new google.maps.Marker({
        map: map,
        position: geocoder,
        icon: icon.icon,
        shadow: icon.shadow
      });
      bindInfoWindow(marker, map, infoWindow, html);
    }
  });
4

1 に答える 1

0

説明

これは、グローバル位置座標を DMS 形式7 05.16' N, 171 21.8' Eから のような 10 進数形式に変換する必要があるようです22.621177, 120.298311。あなたのサンプル88秒数は、その位置で許可されている 60 秒を超えています。

この関数は、DMS から Decimal 形式への変換の難しい部分を行います。値が許容範囲内にあることを検証したり、余分なユニットを次に大きなユニット位置に移動したりすることはありません。

実際の例: http://ideone.com/h2xwAc

コード

<?php

function DMS2Decimal($degrees = 0, $minutes = 0, $seconds = 0, $direction = 'n') {
     //converts DMS coordinates to decimal
     //returns false on bad inputs, decimal on success

     //direction must be n, s, e or w, case-insensitive
     $d = strtolower($direction);
     $ok = array('n', 's', 'e', 'w');

     //degrees must be integer between 0 and 180
     if(!is_numeric($degrees) || $degrees < 0 || $degrees > 180) {
          $decimal = false;
     }
     //minutes must be integer or float between 0 and 59
     elseif(!is_numeric($minutes) || $minutes < 0 || $minutes > 59) {
          $decimal = false;
     }
     //seconds must be integer or float between 0 and 59
     elseif(!is_numeric($seconds) || $seconds < 0 || $seconds > 59) {
          $decimal = false;
     }
     elseif(!in_array($d, $ok)) {
          $decimal = false;
     }
     else {
          //inputs clean, calculate
          $decimal = $degrees + ($minutes / 60) + ($seconds / 3600);

          //reverse for south or west coordinates; north is assumed
          if($d == 's' || $d == 'w') {
               $decimal *= -1;
          }
     }

     return $decimal;
}



echo "x: " . DMS2Decimal($degrees = 7, $minutes = 5, $seconds = 16, $direction = 'n');

echo "y: " . DMS2Decimal($degrees = 171, $minutes = 21, $seconds = 8, $direction = 'e');

出力

x: 7.0877777777778y: 171.35222222222

コードへの挿入

回答のこの部分はテストされておらず、おそらく間違った場所にあることに注意してください。これは、私が問題にどのようにアプローチするかの概要を示すためだけです。いずれの値についても検証テストがないことに注意してください。

function load(User_Id, x, y) {

// if the x coordinate is not a number then assume it is in DMS format and convert
    if (!is_numeric(x)) {
        x = DMS2Decimal(x)
    }

// if the y coordinate is not a number then assume it is in DMS format and convert
    if (!is_numeric(y)) {
        y = DMS2Decimal(y)
    }

    var map = new google.maps.Map(document.getElementById("map_canvas"), {
        center: new google.maps.LatLng(x,y),
        zoom: 13,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    });

}
于 2013-07-13T04:02:24.163 に答える