Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/421.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 修改脚本以使用纬度/经度而不是地址';s_Javascript_Google Maps_Google Polyline - Fatal编程技术网

Javascript 修改脚本以使用纬度/经度而不是地址';s

Javascript 修改脚本以使用纬度/经度而不是地址';s,javascript,google-maps,google-polyline,Javascript,Google Maps,Google Polyline,这个演示脚本在谷歌地图上从一个点到所有其他点绘制直线(多段线),但它对所有点使用地址(地图中心除外)。如何修改此脚本以使用所有纬度和经度数据而不是地址数据 <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> <title>Google Maps API Geocoding Demo</

这个演示脚本在谷歌地图上从一个点到所有其他点绘制直线(多段线),但它对所有点使用地址(地图中心除外)。如何修改此脚本以使用所有纬度和经度数据而不是地址数据

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
<title>Google Maps API Geocoding Demo</title> 
<script src="http://maps.google.com/maps/api/js?sensor=false" 
      type="text/javascript"></script>
</head> 
<body>
<div id="map" style="width: 1280px; height: 1024px;"></div>

<script type="text/javascript">
 //add locations
var map = new google.maps.Map(document.getElementById('map'), {
  zoom: 2,
  center: new google.maps.LatLng(35.00, -25.00),
  mapTypeId: google.maps.MapTypeId.TERRAIN
});

var address1 = '60033';

var gc = new google.maps.Geocoder();
gc.geocode({'address': address1}, function (res1, status) {

    var hub = res1[0].geometry.location;
    new google.maps.Marker({
        position: res1[0].geometry.location,
        map: map
      });

    geocodeLine(hub, '44145');  
    geocodeLine(hub, '03103');
    geocodeLine(hub, '30236');
    geocodeLine(hub, '18106');
    geocodeLine(hub, '64147');
    geocodeLine(hub, '86401');
    geocodeLine(hub, '75110');
    geocodeLine(hub, '56001');
    geocodeLine(hub, '80239');
    geocodeLine(hub, '95776');
});   

function geocodeLine(hub, address)
{
    var gc = new google.maps.Geocoder();

    gc.geocode({'address': address}, function (res, status) { 
        if (status == google.maps.GeocoderStatus.OK) {

          new google.maps.Marker({
            position: res[0].geometry.location,
            map: map
          }); 

          new google.maps.Polyline({
            path: [
              hub,
              res[0].geometry.location
            ],
            strokeColor: '#FF0000',
            geodesic: true,
            map: map
            });
        }
    });
}
</script>
</body>
</html>

谷歌地图API地理编码演示
//添加位置
var map=new google.maps.map(document.getElementById('map'){
缩放:2,
中心:新google.maps.LatLng(35.00,-25.00),
mapTypeId:google.maps.mapTypeId.TERRAIN
});
var address1='60033';
var gc=new google.maps.Geocoder();
gc.geocode({'address':address1},函数(res1,状态){
var hub=res1[0]。geometry.location;
新的google.maps.Marker({
位置:res1[0]。geometry.location,
地图:地图
});
地理编码线(枢纽,'44145');
地理编码线(枢纽,'03103');
地理编码线(枢纽,'30236');
地理编码线(hub,'18106');
地理编码线(枢纽,'64147');
地理编码线(枢纽,'86401');
地理编码线(枢纽,'75110');
地理编码线(枢纽,'56001');
地理编码线(枢纽,'80239');
地理编码线(枢纽,'95776');
});   
功能地理编码线(集线器、地址)
{
var gc=new google.maps.Geocoder();
gc.geocode({'address':address},函数(res,status){
if(status==google.maps.GeocoderStatus.OK){
新的google.maps.Marker({
位置:res[0]。geometry.location,
地图:地图
}); 
新的google.maps.Polyline({
路径:[
中心
res[0]。geometry.location
],
strokeColor:“#FF0000”,
测地线:正确,
地图:地图
});
}
});
}

删除对地理编码器的调用,并将其替换为类似问题:,使第0个位置成为“中心”。阵列中的对象具有
lat
lng
属性,因此它们可以用作对象:

//添加位置
变量位置=[
{地址:60033,lat:42.4444701,lng:-88.6144839},
{地址:44145,lat:41.4470451,lng:-81.9207423},
{地址:03103,lat:42.9561485,lng:-71.44181},
{地址:30236,lat:33.5213067,lng:-84.3226488},
{地址:18106,lat:40.5825021,lng:-75.6149893},
{地址:64147,lat:38.8524485,lng:-94.5469705},
{地址:86401,lat:35.1115663,lng:-113.8584737},
{地址:75110,lat:32.0302037,lng:-96.5143087},
{地址:56001,lat:44.1223003,lng:-93.9674371},
{地址:80239,lat:39.8086537,lng:-104.8337879},
{地址:95776,lat:38.6944843,lng:-121.6967438}];
函数initMap(){
var map=new google.maps.map(document.getElementById('map'){
缩放:2,
中心:新google.maps.LatLng(35.00,-25.00),
mapTypeId:google.maps.mapTypeId.TERRAIN
});
新的google.maps.Marker({
位置:位置[0],
标题:“+位置[0]。地址,
地图:地图
});
对于(变量i=1;i
html,body,#map{
身高:100%;
宽度:100%;
边际:0px;
填充:0px
}


地理编码比不地理编码更复杂。是否尝试进行所需更改?单击图标(横向/纵向数据点)时是否可以添加信息窗口?我添加了--new google.maps.InfoWindow({content:[locations[I].addedbyme});--,但我认为我的问题在于错误地调用adddomstener。