Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.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
Google maps 谷歌地图Api-从点阵列绘制路线_Google Maps - Fatal编程技术网

Google maps 谷歌地图Api-从点阵列绘制路线

Google maps 谷歌地图Api-从点阵列绘制路线,google-maps,Google Maps,我想连接谷歌地图上的8个点,以便它们共享线路(道路)。我想点击点云上显示的描述点。目标是显示汽车点到点的路线 我有脚本,使点地图,但我不知道如何连接标记 var MapPoints = '[{"address":{"address":"plac Grzybowski, Warszawa, Polska","lat":"52.2360592","lng":"21.002903599999968"},"title":"Warszawa"},{"address":{"address":"Jana Pa

我想连接谷歌地图上的8个点,以便它们共享线路(道路)。我想点击点云上显示的描述点。目标是显示汽车点到点的路线

我有脚本,使点地图,但我不知道如何连接标记

var MapPoints = '[{"address":{"address":"plac Grzybowski, Warszawa, Polska","lat":"52.2360592","lng":"21.002903599999968"},"title":"Warszawa"},{"address":{"address":"Jana Paw\u0142a II, Warszawa, Polska","lat":"52.2179967","lng":"21.222655600000053"},"title":"Wroc\u0142aw"},{"address":{"address":"Wawelska, Warszawa, Polska","lat":"52.2166692","lng":"20.993677599999955"},"title":"O\u015bwi\u0119cim"}]';

var MY_MAPTYPE_ID = 'custom_style';
function initialize() {

if (jQuery('#map').length > 0) {

    var locations = jQuery.parseJSON(MapPoints);

    window.map = new google.maps.Map(document.getElementById('map'), {
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        scrollwheel: false
    });

    var infowindow = new google.maps.InfoWindow();
    var bounds = new google.maps.LatLngBounds();

    for (i = 0; i < locations.length; i++) {
        marker = new google.maps.Marker({
            position: new google.maps.LatLng(locations[i].address.lat, locations[i].address.lng),
            map: map
        });

        bounds.extend(marker.position);

        google.maps.event.addListener(marker, 'click', (function (marker, i) {
            return function () {
                infowindow.setContent(locations[i]['title']);
                infowindow.open(map, marker);
            }
        })(marker, i));
    }

    map.fitBounds(bounds);

    var flightPlanCoordinates = [
        new google.maps.LatLng(37.772323, -122.214897),
        new google.maps.LatLng(21.291982, -157.821856),
        new google.maps.LatLng(-18.142599, 178.431),
        new google.maps.LatLng(-27.46758, 153.027892)
    ];
    var flightPath = new google.maps.Polyline({
        path: flightPlanCoordinates,
        strokeColor: "#FF0000",
        strokeOpacity: 1.0,
        strokeWeight: 2
    });

    var flightPath = responseArray.map(function (item) {
        return new google.maps.LatLng(item.latitude, item.longitude);
    });

    var listener = google.maps.event.addListener(map, "idle", function () {
        map.setZoom(12);
        google.maps.event.removeListener(listener);
    });
 }
 }
 google.maps.event.addDomListener(window, 'load', initialize);
var MapPoints='[{“地址”:{“地址”:“plac Grzybowski,Warszawa,Polska”,“lat”:“52.2360592”,“lng”:“21.00290359999968”},“标题”:“Warszawa”},{“地址”:“地址”:“Jana Paw\u0142a II,Warszawa,Polska”,“lat”:“52.2179967”,“lng”:“21.222655600000053”},“标题”:“Wroc\u0142aw”},“地址”:“地址”:“Warszawa,Warszawa,Polska”,“216692”,“lng”:“20.9936775999955”},“标题”:“O\u015bwi\u0119cim”}];
var MY_MAPTYPE_ID='custom_style';
函数初始化(){
if(jQuery('#map')。长度>0){
var locations=jQuery.parseJSON(MapPoints);
window.map=new google.maps.map(document.getElementById('map'){
mapTypeId:google.maps.mapTypeId.ROADMAP,
滚轮:错误
});
var infowindow=new google.maps.infowindow();
var bounds=new google.maps.LatLngBounds();
对于(i=0;i
  • 将标记与google.maps.Polyline连接(就像您正在尝试的那样)

  • 创建一个空数组:
    var flightPlanCoordinates=[]

  • 将标记(google.maps.LatLng对象)的坐标推送到用于多段线的坐标数组中:
    flightplancoardinates.push(marker.getPosition())

  • 设置多段线的
    map
    选项:
    map:map
    (在PolylineOptions对象中)

工作代码片段:

var MapPoints='[{“地址”:{“地址”:“plac Grzybowski,Warszawa,Polska”,“lat”:“52.2360592”,“lng”:“21.00290359999968”},“标题”:“Warszawa”},{“地址”:“地址”:“Jana Paw\u0142a II,Warszawa,Polska”,“lat”:“52.2179967”,“lng”:“21.222655600000053”},“标题”:“Wroc\u0142aw”},“地址”:“地址”:“Warszawa,Warszawa,Polska”,“216692”,“lng”:“20.9936775999955”},“标题”:“O\u015bwi\u0119cim”}];
var MY_MAPTYPE_ID='custom_style';
函数初始化(){
if(jQuery('#map')。长度>0){
var locations=jQuery.parseJSON(MapPoints);
window.map=new google.maps.map(document.getElementById('map'){
mapTypeId:google.maps.mapTypeId.ROADMAP,
滚轮:错误
});
var infowindow=new google.maps.infowindow();
var FlightPlan坐标=[];
var bounds=new google.maps.LatLngBounds();
对于(i=0;i
html,
身体,
#地图{
高度:500px;
宽度:500px;
边际:0px;
填充:0px
}

var flightPath = new google.maps.Polyline({
    map: map,
    path: flightPlanCoordinates,
    strokeColor: "#FF0000",
    strokeOpacity: 1.0,
    strokeWeight: 2
});