Basic KML with Google Map API not working

孤街醉人 提交于 2021-01-28 07:05:30

问题


I tried my first Google Map API with KML and it bombed on me. Just seem to be a very basic problem but just can't get it to work.

Here is the script tag:

 <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"> </script>

Here is the Javascript:

$(document).ready(function () {
 map_center = new google.maps.LatLng(-34.397, 150.644);
 var mapOptions = {
      zoom: 8,
      center: map_center
  };
  var kml_map = new google.maps.Map(document.getElementById('map_div'), mapOptions); 
  var kml_layer = new google.maps.KmlLayer({
          preserveViewport: true,
         url: 'http://someurl/mykml.kml' //Of course, I am using a valid URL here for "someurl" 
   }); 
  kml_layer.setMap(kml_map);
});

And here is the KML file:

 <?xml version="1.0" encoding="UTF-8"?>
 <kml xmlns="http://www.opengis.net/kml/2.2">
  <Placemark>
 <name>My placemark!</name>
 <description>Some description of my placemark.</description>
 <Point>
 <coordinates>-34.397, 150.644</coordinates>
 </Point>
 </Placemark>
 </kml>

I do not see the placemark. I see the GoogleMap of the whole planet with no zoom... nothing else. Where am I going wrong? No errors in the console either.


回答1:


KML coordinates are longitude,latitude; no spaces allowed.



来源:https://stackoverflow.com/questions/21815852/basic-kml-with-google-map-api-not-working

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