0

私はそのコードを使用して、自分のアプリで地理位置情報を取得しています。移動中もうまく機能します。地理位置情報から固定緯度経度の終点 (固定) までの計算を作成するために、いくつかの行を追加しました。コードの原点が受け入れられない理由がわかりません (fireBug は、プロパティ [オブジェクト オブジェクト] を呼び出せないと言っています) が、わかりません。gmaps v3 に関するコードは次のとおりです。

//image for the marker
var imageLoc = '../../img/bbb3.gif' 
var map;
//initialize the maps
function initialize() {
  //call directionsService and Display for the route
  var directionsService = new google.maps.DirectionsService();
  var directionsDisplay = new google.maps.DirectionsRenderer();
  //map option
  var mapOptions = {
    zoom: 8,
    center: new google.maps.LatLng(44.49489, 11.34262),
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };
  map = new google.maps.Map(document.getElementById('map'),
      mapOptions);
  //create the marker for the geolocation
  marker = new google.maps.Marker({ 
          map: map,
          icon: imageLoc
  });
  //call updatePos() function
  updatePos();

  directionsDisplay.setMap(map);
  directionsDisplay.setPanel(document.getElementById('panel'));
      var request = {
        //origin is the marker of my geolocation
        origin: marker,
        //destination is a fxed position
        destination: new google.maps.LatLng(44.496099,11.340246),
        travelMode: google.maps.DirectionsTravelMode.WALKING
     };

     directionsService.route(request, function (response, status) {
       if (status == google.maps.DirectionsStatus.OK) {
          directionsDisplay.setDirections(response);
        }
      });
}
var i;
//here I set my marker (if i==0 -> first run)
function updatePos(){
var options = {
    timeout: 60000, enableHighAccuracy: true
};
var myUpdatedPos = navigator.geolocation.watchPosition(onSuccess, onError, options);
function onSuccess(position) {
    if (i==0){
        marker = new google.maps.Marker({
                        position: new google.maps.LatLng(position.coords.latitude, position.coords.longitude),
                        map: map                       
                    });
    }
    i++;
    //here I update the position
     newLatlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
    marker.setPosition(newLatlng);
}

// onError Callback receives a PositionError object
//
    function onError(error) {
        alert('code: '    + error.code    + '\n' +
        'message: ' + error.message + '\n');
    }
}
google.maps.event.addDomListener(window, 'load', initialize);

誰にも理由はありますか?

敬具

ブルス

4

1 に答える 1