How to retrieve google Markers

99封情书 提交于 2019-12-13 08:04:11

问题


How to retrieve all existing markers on the public map created by me in javascript.

In html I am adding following tag.

<iframe src="https://www.google.com/maps/d/u/0/embed?mid=zJ463bGh1PYM.kWHWVlcByQeU" width="640" height="480"></iframe>

Now I want to extract all the markers present on this map in Javascript.

Please help me in this.


回答1:


  1. click on the

  1. choose "Download KML"
  2. check the "Keep data up to date with network link KML (only usable online)."
  3. rename the resulting .kmz file as .zip
  4. open the contained .kml file
<?xml version='1.0' encoding='UTF-8'?>
<kml xmlns='http://www.opengis.net/kml/2.2'>
    <Document>
        <name>Untitled layer</name>
        <NetworkLink>
            <name>my-map</name>
            <Link>
                <href>http://mapsengine.google.com/map/kml?mid=zJ463bGh1PYM.kWHWVlcByQeU&amp;lid=zJ463bGh1PYM.ko7uxR2p2yu4</href>
            </Link>
        </NetworkLink>
    </Document>
</kml>
  1. that contains the external link to the KML that describes your map (http://mapsengine.google.com/map/kml?mid=zJ463bGh1PYM.kWHWVlcByQeU&amp;lid=zJ463bGh1PYM.ko7uxR2p2yu4). Load that on a Google Maps Javascript API v3 map using KmlLayer.

working code snippet:

function initialize() {
    var map = new google.maps.Map(
    document.getElementById("map_canvas"), {
        center: new google.maps.LatLng(37.4419, -122.1419),
        zoom: 13,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    });

    var layer = new google.maps.KmlLayer({
        url: "http://mapsengine.google.com/map/kml?mid=zJ463bGh1PYM.kWHWVlcByQeU&amp;lid=zJ463bGh1PYM.ko7uxR2p2yu4",
        map: map
    });

}
google.maps.event.addDomListener(window, "load", initialize);
html, body, #map_canvas {
    height: 100%;
    width: 100%;
    margin: 0px;
    padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js"></script>
<div id="map_canvas" style=border: 2px solid #3872ac;"></div>


来源:https://stackoverflow.com/questions/28642206/how-to-retrieve-google-markers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!