Display My Maps using the Google Maps API

When I created custom My Maps and default, Google allows you to share using an approach iframe

.

However, this is very slow and I want to do it using the JS API.

What's the easiest way to do this?

0


source to share


1 answer


One option is to use Exported KML from custom My Maps to display the data in the Google Maps v3 KmlLayer Javascript API .

snippet: (data from this MyMap )



var geocoder;
var map;

function initialize() {
  var map = new google.maps.Map(
    document.getElementById("map_canvas"), {
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });
  var layer = new google.maps.KmlLayer({
    url: "http://www.google.com/maps/d/kml?mid=zNPjLbo835mE.k3TvWfqGG-AU",
    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"></div>
      

Run codeHide result


+2


source







All Articles