问题
I tried to draw boundaries of HK island by using KML.
Supposed, there would be polygon lines on the map of the Hong Kong island.
But nothing shown. Why?
Any other methods to import data with coordinates of polygon to google map api?
THANKS !
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0">
<meta charset="utf-8">
<script src="http://maps.google.com/maps/api/js?v=3&sensor=false" type="text/javascript"></script>
<title>KML Layers</title>
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 100%;
}
</style>
</head>
<body>
<body onload="initMap()">
<div id="map"></div>
<script>
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 12,
center: {lat: 22.264316, lng: 114.187260}
});
var ctaLayer = new google.maps.KmlLayer({
url: 'http://o3xmaps.com/gis-map-projects/201510/hkisland.kml',
map: map
});
}
</script>
</body>
</html>
回答1:
Your KML returns a KmlStatus of Kml Status:INVALID_DOCUMENT:
http://www.geocodezip.com/v3_GoogleEx_layer-kml_linktoB.html?filename=http://o3xmaps.com/gis-map-projects/201510/hkisland.kml
Your KML is not valid.
Sorry
This feed does not validate.
line 10, column 27: Not a valid color: 0FFFFFF (11 occurrences) [help]
<PolyStyle><color>0FFFFFF</color></PolyStyle>
^
line 2267, column 29: XML parsing error: :2267:29: not well-formed (invalid token) [help]
<name>A06 堅摩 Kennedy Town & Mount Davis</name>
If I make it valid: http://feedvalidator.org/check.cgi?url=http%3A%2F%2Fwww.geocodezip.com%2Fgeoxml3_test%2Fkml%2Fhkisland.kml
It works for me
来源:https://stackoverflow.com/questions/33056005/google-map-api-kml-layer