Google方向不起作用

Google方向不起作用

本文介绍了Google方向不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试为我当前的位置和标记坐标指示方向。所以我使用getcurrentposition获取经度和纬度。然后,我标记它。

 函数initialize(){
directionsDisplay = new google.maps.DirectionsRenderer();
var node = new google.maps.LatLng(-7.276442,112.791174);
var mapOptions = {
zoom:15,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map'),
mapOptions);
directionsDisplay.setMap(map);

navigator.geolocation.getCurrentPosition(function(position){
pos = new google.maps.LatLng(position.coords.latitude,
position.coords.longitude);

var marker = new google.maps.Marker({
position:pos,
map:map,
title:'Lokasi Anda'
}) ;
var marker1 = new google.maps.Marker({
position:node,
map:map,
title:'Lokasi Anda'
});

map.setCenter(pos);
},function(){
handleNoGeolocation(true);
});

}

然后,我使用这个函数来计算它。

 函数calcRoute(){

var request = {
origin:pos,
destination:node,
travelMode:google.maps.DirectionsTravelMode.DRIVING
};

directionsService.route(request,function(response,status){
if(status == google.maps.DirectionsStatus.OK){
directionsDisplay.setDirections(response);
}
});
}

但是为什么我不能从 pos 节点。任何建议?如果我调用calcRoute函数(并传入pos和node位置,它可以提供任何建议吗?

(在美国)和点位于哪里(Raya Its,Sukolilo,Surabaya City,East Java 60117,Republic of Indonesia)。DirectionsService返回状态ZERO_RESULTS。



 函数calcRoute(pos,node){
var directionsService = new google.maps.DirectionsService();
var request = {
origin:pos,
destination:node,
travelMode:google.maps.DirectionsTravelMode.DRIVING
};

directionsService.route(request,function(响应,状态){
if(status == google.maps.DirectionsStatus.OK){
directionsDisplay.setDirections(response);
} else {alert(Directions fai领导:+状态); }
});
}


I try to make directions for my current position and marker coordinate. so i get latitude and longitude using getcurrentposition. then, i mark it.

function initialize() {
  directionsDisplay = new google.maps.DirectionsRenderer();
  var node = new google.maps.LatLng(-7.276442,112.791174);
  var mapOptions = {
    zoom: 15,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };
  map = new google.maps.Map(document.getElementById('map'),
      mapOptions);
  directionsDisplay.setMap(map);

    navigator.geolocation.getCurrentPosition(function(position) {
      pos = new google.maps.LatLng(position.coords.latitude,
                                       position.coords.longitude);

      var marker = new google.maps.Marker({
            position : pos,
            map: map,
            title:'Lokasi Anda'
      });
      var marker1 = new google.maps.Marker({
            position : node,
            map: map,
            title:'Lokasi Anda'
      });

      map.setCenter(pos);
    }, function() {
      handleNoGeolocation(true);
    });

}

then, I calculate it using this function.

function calcRoute() {

  var request = {
      origin:pos,
      destination:node,
      travelMode: google.maps.DirectionsTravelMode.DRIVING
  };

  directionsService.route(request, function(response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
      directionsDisplay.setDirections(response);
    }
  });
}

but why i can't see direction from pos to node. any suggestion ?

解决方案

If I call the calcRoute function (and pass in the "pos" and "node" locations, it can't find directions between where I am (in the US) and where the point is located (Raya Its, Sukolilo, Surabaya City, East Java 60117, Republic of Indonesia). The DirectionsService returns a status of "ZERO_RESULTS".

working example

function calcRoute(pos,node) {
var directionsService = new google.maps.DirectionsService();
  var request = {
      origin:pos,
      destination:node,
      travelMode: google.maps.DirectionsTravelMode.DRIVING
  };

  directionsService.route(request, function(response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
      directionsDisplay.setDirections(response);
    } else { alert("Directions failed: "+status); }
  });
}

这篇关于Google方向不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 17:25