首页 > javascript > Google Maps API + Google Maps Engine /我的地图

Google Maps API + Google Maps Engine /我的地图 (Google Maps API + Google Maps Engine / My Maps)

问题

我已经使用谷歌地图引擎将包含图层和形状的自定义地图嵌入到我的网页中,但它将停止使用,而替代品是谷歌我的地图,这是轻量级的,但似乎满足我的需求。

现在问我的问题。我正在使用Google Maps API在我的网页上显示地图,我还有来自“我的地图”的地图的嵌入代码,我想将它们组合在一起。因此,我想加载Google Maps API并显示我喜欢的任何区域,添加标记和所有内容,然后在其上(或在其下)显示“我的地图”中特定地图的图层和形状。

就像我说的,我有自己的嵌入代码,mapId格式为“abcdefgh.abcdefgh”。

现在,查看Google Maps API,有一个(已弃用的)“MapsEngineLayer”功能可按ID加载特定的地图引擎图层,但无法在我找到的“我的地图”中找到特定的图层ID,另外还有我想要一个mapID的所有图层,但该函数需要layerId或LayerKey。

那么,有没有办法将“我的地图”中的地图包含在Google Maps API的常规显示中?

解决方法

您也可以下载这样的地图作为KML,下载URL就像

https://www.google.com/maps/d/kml?mid=themymaps.mapid

它没有记录,但是当我使用这个URL创建一个KmlLayer时,它现在适用于我(它应该工作的时间长,他们没有修改下载程序)。

示例(原始地图)

function initialize() {

  var map = new google.maps.Map(document.getElementById('map-canvas'), {
      zoom: 0,
      center: new google.maps.LatLng(0, 0)
    }),

    myMapsId = 'z4jtZiEBVczE.kp_M0KHEIung';
  new google.maps
    .KmlLayer({
      map: map,
      url: 'https://www.google.com/maps/d/kml?mid=' + myMapsId
    });
}

google.maps.event.addDomListener(window, 'load', initialize);
  html,
  body,
  #map-canvas {
    height: 100%;
    margin: 0px;
    padding: 0px
  }
<script src="https://maps.googleapis.com/maps/api/js?v=3"></script>
<div id="map-canvas"></div>


问题

I've used Google Maps Engine to embed customized maps with layers and shapes into my web page, but it is going to be discontinued, and the replacement is Google My Maps, which is lightweight, but seems to serve my needs.

Now to my question. I am using Google Maps API to display a map on my web page, and I also have the embed code for a map from My Maps, and I want to combine them. So I want to load Google Maps API and display whatever area I like, adding markers and everything, and then on top of that (or under that) display the layers and shapes from a specific map in My Maps.

Like I said, I have the embed code, which works on its own, and the mapId is in the format "abcdefgh.abcdefgh".

Now, looking in the Google Maps API, there is a (deprecated) "MapsEngineLayer" function to load a specific Maps Engine Layer by ID, but there is no way to find out a specific layer ID in My Maps that I have found, plus I want all the layers of one mapID, but that function requires a layerId or LayerKey.

So, is there a way to include a map from "my maps" into the normal display from the Google Maps API?

解决方法

You may also download such a map as KML, the download-URL is something like

https://www.google.com/maps/d/kml?mid=themymaps.mapid

It's not documented, but currently it works for me when I use this URL to create a KmlLayer(it should work as long they didn't modify the download-procedure).

Example(original map)

function initialize() {

  var map = new google.maps.Map(document.getElementById('map-canvas'), {
      zoom: 0,
      center: new google.maps.LatLng(0, 0)
    }),

    myMapsId = 'z4jtZiEBVczE.kp_M0KHEIung';
  new google.maps
    .KmlLayer({
      map: map,
      url: 'https://www.google.com/maps/d/kml?mid=' + myMapsId
    });
}

google.maps.event.addDomListener(window, 'load', initialize);
  html,
  body,
  #map-canvas {
    height: 100%;
    margin: 0px;
    padding: 0px
  }
<script src="https://maps.googleapis.com/maps/api/js?v=3"></script>
<div id="map-canvas"></div>

相似信息