【问题标题】:How can I get aerial view with the Google Maps Javascript API如何使用 Google Maps Javascript API 获得鸟瞰图
【发布时间】:2015-09-27 02:03:21
【问题描述】:

我正在尝试配置一个谷歌地图对象来向我展示鸟瞰图:

var map;
function initMap() {
    detectBrowser();

    map = new google.maps.Map(document.getElementById('map'), {
        center: {lat: 34.05, lng: -118.25},
        mapTypeId: google.maps.MapTypeId.HYBRID,
        zoom: 6,
        heading: 90,
        tilt: 45
    });

    //map.enableRotation()

    map.setTilt(45);
    GMap2.enableRotation();


    //GLargeMapControl3D

}

function detectBrowser() {
    var useragent = navigator.userAgent;
    var mapdiv = document.getElementById("map");

    if (useragent.indexOf('iPhone') != -1 || useragent.indexOf('Android') != -1 ) {
        mapdiv.style.width = '100%';
        mapdiv.style.height = '100%';
    } else {
        mapdiv.style.width = '1000px';
        mapdiv.style.height = '800px';
    }

}

我可以看到 45 度的视野。但不是鸟瞰图。我也没有看到相机倾斜控件。

不知何故,这个网址似乎有它:https://www.google.com/maps/@25.7541032,-80.192274,407a,35y,78.6t/data=!3m1!1e3

从这里:https://productforums.google.com/forum/#!topic/maps/rLDvD6qFsS4

【问题讨论】:

  • GMap2.enableRotation 是 Google Maps API v2 函数,但您的其余代码看起来像是在使用 Google Maps API v3。这两个 API 不是交叉兼容的;您可能应该删除该行以及使用 API v2 代码的任何其他行。见developers.google.com/maps/articles/v2tov3
  • 谢谢邓肯,我做到了。至于鸟瞰图,可能v3不支持。

标签: javascript google-maps google-maps-api-3


【解决方案1】:

将您的 tilt 值更改为 0。

var map;
function initMap() {
    detectBrowser();

    map = new google.maps.Map(document.getElementById('map'), {
        center: {lat: 34.05, lng: -118.25},
        mapTypeId: google.maps.MapTypeId.HYBRID,
        zoom: 18,
        heading: 90,
        tilt: 0
    });

    //map.enableRotation()

    //map.setTilt(45);
    GMap2.enableRotation();


    //GLargeMapControl3D

}

function detectBrowser() {
    var useragent = navigator.userAgent;
    var mapdiv = document.getElementById("map");

    if (useragent.indexOf('iPhone') != -1 || useragent.indexOf('Android') != -1 ) {
        mapdiv.style.width = '100%';
        mapdiv.style.height = '100%';
    } else {
        mapdiv.style.width = '1000px';
        mapdiv.style.height = '800px';
    }
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2023-03-10
  • 1970-01-01
  • 1970-01-01
  • 2021-04-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-24
相关资源
最近更新 更多