问题描述
我想为我自己基于PHP的网站上,有项目我的谷歌地图创建KML层。
Hey guys I am trying to create a KML layer for my google map on my own PHP based website for a project.
因为我想用似乎并没有为我工作的API的URL。该API可以在这里找到。 。其电动汽车充电站是psented在地图上$ P $。
The URL for the API I want to use doesn't seem to work for me. The API can be found here. http://openchargemap.org/site/develop/api. Its for electric vehicle charging stations to be presented on the map.
在使用其他的API和谷歌的例子,它们做工精细用我的code,使用一个我需要将无法工作。
When using other APIs and googles examples, they work fine with my code, using the one I need will not work.
var kmlLayer = new google.maps.KmlLayer({
url: 'http://api.openchargemap.io/v2/poi/?output=kml&countrycode=GB&maxresults=500',
suppressInfoWindows: true,
map: map
});
以上code是我的initialise地图功能里面。
The above code is inside my initialise map function.
我已经尝试了其中没有他们的工作URL的API的不同变化。上面的例子是英国的结果与输出设置为KML最大值500。
I have tried different variations of the API for the url which none of them work. The example above is for UK results with a maximum of 500 with the output set to KML.
我已经注意到这可能是有用的是,当这个API被输入与输出为KML浏览器,在本地下载为无法识别的文件,其中为开发者页面和其他API直接下载作为KML的谷歌的样本。
What I have noticed which could be useful is that when this API is entered into the browser with the output as KML, it downloads locally as an unrecognised file where as the google samples on the developers page and other APIS download directly as KML's.
在用记事本打开该文件无法识别++是我想和可以保存为可能被上载和使用的方式KML的KML功能。这让我觉得有可能是一些错误的Opencharge地图API。但我所有的新本,所以任何帮助AP preciated!
The unrecognised file when opened with Notepad++ is the KML functionality that I want and can be saved as a KML which could be uploaded and used that way. Which makes me think there could be something wrong with the Opencharge map API. But I am all new to this so any help is appreciated!
谢谢你们!
推荐答案
的 KmlLayer
的的getStatus()
方法,而你的情况返回 FETCH_ERROR
。这意味着谷歌API已经无法下载KML中为您服务。他们用自己的服务器连接到Opencharge API和下载KML,所以很难确定什么原因。但是,即使当您尝试下载KML文件自己,上载和负载从服务器,您将获得 INVALID_DOCUMENT
错误,表示文件是无效的KML,或谷歌地图API无法解析它。您可以检查在
The KmlLayer
has getStatus()
method, which in your case returns FETCH_ERROR
. This means that google api has trouble downloading the KML for you. They use their own servers to connect to the Opencharge api and download the KML so it's hard to determine what's the cause. But even when you try to download the KML file yourself, upload it and load from your server, you would get INVALID_DOCUMENT
error, meaning the file is not valid KML, or the google maps API cannot parse it. You can check the list of possible statuses in the google maps js api docs.
所以,是的,肯定是与API的问题,不是你的code。你可以做的是在服务器上创建一个脚本,将加载KML,分析它,并创建一个有效的KML这会你再喂到API。所以,你需要:
So yes, there is definitely a problem with the API, not your code. What you can do is create a script on your server which would load the KML, parse it, and create a valid KML which would you then feed to the API. So, you need:
- 从您的服务器加载的URL并解析它作为XML(KML是XML标记)。 是一个例子,如何在PHP中做到这一点。
- 从已解析的XML创建一个只包含位置配位和所有必要的数据你自己的有效的KML文件。
- 请你的脚本返回这个新创建的KML。
-
加载脚本的网址,而不是原来的API,例如:
- Load the url from your server and parse it as XML (KML is in XML notation). This is an example how to do this in php.
- From parsed XML create your own valid KML file containing just the location coordinations and any necessary data.
- Make your script return this newly created KML.
Load your script's url instead of the original API, e.g:
VAR kmlLayer =新google.maps.KmlLayer({
网址:HTTP:// yourserver / yourscript和放大器; optionalparameters',
SUP pressInfoWindows:真实,
地图:地图
});
这篇关于GOOGLEMAPS Javascript API第KML层 - 使用开放式收费地图API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!