AJAX JQuery加载KML层
我正在尝试使用jqueryajax请求在googlemapsapi3.0上使用一个KML层。这就是我到目前为止所做的(没有工作)AJAX JQuery加载KML层,jquery,ajax,google-maps,kml,Jquery,Ajax,Google Maps,Kml,我正在尝试使用jqueryajax请求在googlemapsapi3.0上使用一个KML层。这就是我到目前为止所做的(没有工作) $(文档).ready(函数(){ $.ajax({ 网址:'https://blahhhhhhhhhh.com/KML_Placemarks.kml', 数据类型:“html”, 成功:功能(数据){ 控制台日志(数据); var Google=new Google.maps.LatLng(37.42228990140251,-122.0822035425683)
$(文档).ready(函数(){
$.ajax({
网址:'https://blahhhhhhhhhh.com/KML_Placemarks.kml',
数据类型:“html”,
成功:功能(数据){
控制台日志(数据);
var Google=new Google.maps.LatLng(37.42228990140251,-122.0822035425683);
变量映射选项={
缩放:18,
中心:谷歌
}
var map=new google.maps.map(document.getElementById('map-canvas'),mapOptions);
var ctaLayer=new google.maps.KmlLayer({
//网址:'http://gmaps-samples.googlecode.com/svn/trunk/ggeoxml/cta.kml'
url:数据
});
ctaLayer.setMap(map);
控制台日志(数据);
}
});
});
Google Maps API文档中的示例只是将cta.kml
文件分配给url
片段。我要做的是用AJAX请求的结果替换它
我觉得这是可能的,因为console.log(data)
的结果读取了它最终需要的内容
谢谢 这是不可能的。其工作原理是让谷歌的服务器读取KML并将其呈现为平铺(因此需要公开)。如果您想在本地加载它,您可以查看第三方KML解析器(如或)或自行滚动以将数据呈现为本机Google Maps Javascript API v3对象,但会影响性能
这应该是可行的(如果“数据”是有效的KML,并且您的KML不太复杂):
$(文档).ready(函数(){
$.ajax({
网址:'https://blahhhhhhhhhh.com/KML_Placemarks.kml',
数据类型:“html”,
成功:功能(数据){
控制台日志(数据);
var Google=new Google.maps.LatLng(37.42228990140251,-122.0822035425683);
变量映射选项={
缩放:18,
中心:谷歌
}
var map=new google.maps.map(document.getElementById('map-canvas'),mapOptions);
var geoXml=new geoXML3.parser({
地图:地图
});
parseKmlString(日期);
ctaLayer.setMap(map);
控制台日志(数据);
}
});
});
我正在尝试此解决方案。我已经在我的页面中添加了geoxmlfull_v3.js库,但是它说geoXML3没有定义。我遗漏了什么吗?我不经常使用geoxml-v3。听起来您没有正确地包含脚本。
<script>
$(document).ready(function(){
$.ajax({
url : 'https://blahhhhhhhhhh.com/KML_Placemarks.kml',
dataType : 'html',
success : function(data) {
console.log(data);
var Google = new google.maps.LatLng(37.42228990140251,-122.0822035425683);
var mapOptions = {
zoom: 18,
center: Google
}
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var ctaLayer = new google.maps.KmlLayer({
//url: 'http://gmaps-samples.googlecode.com/svn/trunk/ggeoxml/cta.kml'
url: data
});
ctaLayer.setMap(map);
console.log(data);
}
});
});
</script>
<script>
$(document).ready(function(){
$.ajax({
url : 'https://blahhhhhhhhhh.com/KML_Placemarks.kml',
dataType : 'html',
success : function(data) {
console.log(data);
var Google = new google.maps.LatLng(37.42228990140251,-122.0822035425683);
var mapOptions = {
zoom: 18,
center: Google
}
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var geoXml = new geoXML3.parser({
map: map
});
geoXml.parseKmlString(date);
ctaLayer.setMap(map);
console.log(data);
}
});
});
</script>