KML - 在地图上显示多个点
KML - show multiple points on map
我想用 KML 文件在 google 地图上显示多个点。我尝试了以下示例,但地图上只显示了第一个点。
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Placemark>
<Point>
<coordinates>-122.0822035425683,37.42228990140251 -122.08223,37.42228</coordinates>
</Point>
</Placemark>
</kml>
我希望上面的示例:
1.在地图上显示2个点
2. 用点显示每个点(目前它是一个图标,而且太大了)。
一个Point
只能有一组坐标。 <coordinates>
元素中的多个点用于 LineString
(行)和 Polygon
路径。如果需要多个标记,则需要多个 <Point>
元素。
已更新 KML:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Placemark>
<Point>
<coordinates>-122.0822035425683,37.42228990140251</coordinates>
</Point>
</Placemark>
<Placemark>
<Point>
<coordinates>-122.08223,37.42228</coordinates>
</Point>
</Placemark>
</kml>
代码片段(使用geoxml3解析KML):
var kmlString = '<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://www.opengis.net/kml/2.2"><Placemark><Point><coordinates>-122.0822035425683,37.42228990140251</coordinates></Point></Placemark><Placemark><Point><coordinates>-122.08223,37.42228</coordinates></Point></Placemark></kml>';
var map;
function initialize() {
var myOptions = {
zoom: 8,
center: {
lat: 42,
lng: -70
}
};
map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
infowindow = new google.maps.InfoWindow({});
geoXml = new geoXML3.parser({
map: map,
infoWindow: infowindow,
singleInfoWindow: true
});
geoXml.parseKmlString(kmlString);
}
google.maps.event.addDomListener(window, 'load', initialize);
html,
body,
#map_canvas {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
<script type="text/javascript" src="http://maps.google.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/geocodezip/geoxml3@master/polys/geoxml3.js"></script>
<div id="map_canvas">
我想用 KML 文件在 google 地图上显示多个点。我尝试了以下示例,但地图上只显示了第一个点。
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Placemark>
<Point>
<coordinates>-122.0822035425683,37.42228990140251 -122.08223,37.42228</coordinates>
</Point>
</Placemark>
</kml>
我希望上面的示例: 1.在地图上显示2个点 2. 用点显示每个点(目前它是一个图标,而且太大了)。
一个Point
只能有一组坐标。 <coordinates>
元素中的多个点用于 LineString
(行)和 Polygon
路径。如果需要多个标记,则需要多个 <Point>
元素。
已更新 KML:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Placemark>
<Point>
<coordinates>-122.0822035425683,37.42228990140251</coordinates>
</Point>
</Placemark>
<Placemark>
<Point>
<coordinates>-122.08223,37.42228</coordinates>
</Point>
</Placemark>
</kml>
代码片段(使用geoxml3解析KML):
var kmlString = '<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://www.opengis.net/kml/2.2"><Placemark><Point><coordinates>-122.0822035425683,37.42228990140251</coordinates></Point></Placemark><Placemark><Point><coordinates>-122.08223,37.42228</coordinates></Point></Placemark></kml>';
var map;
function initialize() {
var myOptions = {
zoom: 8,
center: {
lat: 42,
lng: -70
}
};
map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
infowindow = new google.maps.InfoWindow({});
geoXml = new geoXML3.parser({
map: map,
infoWindow: infowindow,
singleInfoWindow: true
});
geoXml.parseKmlString(kmlString);
}
google.maps.event.addDomListener(window, 'load', initialize);
html,
body,
#map_canvas {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
<script type="text/javascript" src="http://maps.google.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/geocodezip/geoxml3@master/polys/geoxml3.js"></script>
<div id="map_canvas">