第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Google Map API v3-設(shè)置范圍和中心

Google Map API v3-設(shè)置范圍和中心

縹緲止盈 2019-10-23 12:45:56
我最近切換到了Google Maps API V3。我正在研究一個(gè)從數(shù)組繪制標(biāo)記的簡(jiǎn)單示例,但是我不知道如何相對(duì)于標(biāo)記自動(dòng)居中和縮放。我搜尋了包括谷歌自己的文檔在內(nèi)的最高和最低值,但沒(méi)有找到明確的答案。我知道我可以簡(jiǎn)單地取坐標(biāo)的平均值,但是如何設(shè)置縮放比例呢?function initialize() {  var myOptions = {    zoom: 10,    center: new google.maps.LatLng(-33.9, 151.2),    mapTypeId: google.maps.MapTypeId.ROADMAP  }  var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);  setMarkers(map, beaches);}var beaches = [  ['Bondi Beach', -33.890542, 151.274856, 4],  ['Coogee Beach', -33.423036, 151.259052, 5],  ['Cronulla Beach', -34.028249, 121.157507, 3],  ['Manly Beach', -33.80010128657071, 151.28747820854187, 2],  ['Maroubra Beach', -33.450198, 151.259302, 1]];function setMarkers(map, locations) {  var image = new google.maps.MarkerImage('images/beachflag.png',      new google.maps.Size(20, 32),      new google.maps.Point(0,0),      new google.maps.Point(0, 32));    var shadow = new google.maps.MarkerImage('images/beachflag_shadow.png',      new google.maps.Size(37, 32),      new google.maps.Point(0,0),      new google.maps.Point(0, 32));      var lat = map.getCenter().lat();       var lng = map.getCenter().lng();        var shape = {      coord: [1, 1, 1, 20, 18, 20, 18 , 1],      type: 'poly'  };  for (var i = 0; i < locations.length; i++) {    var beach = locations[i];    var myLatLng = new google.maps.LatLng(beach[1], beach[2]);    var marker = new google.maps.Marker({        position: myLatLng,        map: map,        shadow: shadow,        icon: image,        shape: shape,        title: beach[0],        zIndex: beach[3]    });  }}
查看完整描述

3 回答

?
慕碼人8056858

TA貢獻(xiàn)1803條經(jīng)驗(yàn) 獲得超6個(gè)贊

是的,只需聲明新的bounds對(duì)象。


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

然后對(duì)于每個(gè)標(biāo)記,擴(kuò)展您的bounds對(duì)象:


bounds.extend(myLatLng);

map.fitBounds(bounds);

API:google.maps.LatLngBounds


查看完整回答
反對(duì) 回復(fù) 2019-10-23
?
收到一只叮咚

TA貢獻(xiàn)1821條經(jīng)驗(yàn) 獲得超5個(gè)贊

一切都排序了-請(qǐng)查看最后幾行代碼-(bounds.extend(myLatLng); map.fitBounds(bounds);)


function initialize() {

  var myOptions = {

    zoom: 10,

    center: new google.maps.LatLng(0, 0),

    mapTypeId: google.maps.MapTypeId.ROADMAP

  }

  var map = new google.maps.Map(

    document.getElementById("map_canvas"),

    myOptions);

  setMarkers(map, beaches);

}


var beaches = [

  ['Bondi Beach', -33.890542, 151.274856, 4],

  ['Coogee Beach', -33.923036, 161.259052, 5],

  ['Cronulla Beach', -36.028249, 153.157507, 3],

  ['Manly Beach', -31.80010128657071, 151.38747820854187, 2],

  ['Maroubra Beach', -33.950198, 151.159302, 1]

];


function setMarkers(map, locations) {

  var image = new google.maps.MarkerImage('images/beachflag.png',

    new google.maps.Size(20, 32),

    new google.maps.Point(0,0),

    new google.maps.Point(0, 32));

  var shadow = new google.maps.MarkerImage('images/beachflag_shadow.png',

    new google.maps.Size(37, 32),

    new google.maps.Point(0,0),

    new google.maps.Point(0, 32));

  var shape = {

    coord: [1, 1, 1, 20, 18, 20, 18 , 1],

    type: 'poly'

  };

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

  for (var i = 0; i < locations.length; i++) {

    var beach = locations[i];

    var myLatLng = new google.maps.LatLng(beach[1], beach[2]);

    var marker = new google.maps.Marker({

      position: myLatLng,

      map: map,

      shadow: shadow,

      icon: image,

      shape: shape,

      title: beach[0],

      zIndex: beach[3]

    });

    bounds.extend(myLatLng);

  }

  map.fitBounds(bounds);

}

查看完整回答
反對(duì) 回復(fù) 2019-10-23
  • 3 回答
  • 0 關(guān)注
  • 674 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)