PHP Dynamically creating KML for multiple placemarks on map

眉间皱痕 提交于 2019-12-25 09:51:50

问题


Currently struggling with PHP and creating KML from it. I'm using the last.fm API (geoGetevents) to grab events from 'location' (for example, user searches for Manchester) and then (using KML - as I feel more comfortable with it than JS) plot these on a map.

I'm finding that I get invalid KML/KMZ errors when linking to a google map from my feed. Having said that, I know why.. Everything is contained in one file - including the KML that PHP generates.

So with GET variable, the URL is http://example.net/dmp/search.php?city=bristol

Google Maps is ignoring the rest of the URL after the '?' - is there any way I can send the dynamically generated KML to google maps? Maybe creating a separate KML file?

<kml xmlns="http://www.opengis.net/kml/2.2"> <!-- Sets KML header --> 
<Folder> 
<name>Gigs</name> 
      <Placemark><name>As I Lay Dying</name><description> etc

That is the current KML that is created by the PHP.

Hope you can help, and thank you in advance


回答1:


i think i have your answer have you put the link inside a Cdata inside your description this will allow a bubble to appear above the click icon with html in it

good example is a marinetraffic.com

sending dynamically created kml.

add this to your Apache mime.types application/vnd.google-earth.kml+xml kml

at the top of the page that outputs the file put this Header('Content-type: application/vnd.google-earth.kml+xml');

yada yada

ps you can find out alot about the cdata at http://code.google.com/apis/kml/documentation/kml_tut.html

then you need to create a network link file its a kml file that tells google maps ware to look for your server

    <?xml version="1.0" encoding="UTF-8"?>
    <kml xmlns="http://www.opengis.net/kml/2.2">
      <Folder>
        <name>Network Links</name>
        <visibility>0</visibility>
        <open>0</open>
        <description>Network link example 1</description>
        <NetworkLink>
          <name>Random Placemark</name>
          <visibility>0</visibility>
          <open>0</open>
          <description>A simple server-side script that generates a new random
            placemark on each call</description>
          <refreshVisibility>0</refreshVisibility>
          <flyToView>0</flyToView>
          <Link>
<refreshInterval>600.0</refreshInterval>

<refreshMode>onInterval</refreshMode>
            <href>http://yourserver.com/cgi-bin/randomPlacemark.py</href>
          </Link>
        </NetworkLink>
      </Folder>
    </kml>

i added Refresh interval as this will make it auto update

hope this helps chap since you know a alot more php than i do would you mind having a look at my problem ! haha jope this helps




回答2:


your question was a bit fuzzy. let us address how to create dynamic KML files for use with googlemaps simplest interface - the website.

click here for example

the first issue you must be aware of is that, so as to avoid using the website as a dynamic interface, google restricts how often it refreshes the KML (you might have changed it, but google cached it). it will usually be more than 10 minutes before google refreshes its cache.

therefore, the best thing would be to change your KML name, the link to googlemaps embedding and refresh your embedded map.

note: you can write PHP code that spits out a KML and call the PHP file directly from within the googlemaps site.



来源:https://stackoverflow.com/questions/4296840/php-dynamically-creating-kml-for-multiple-placemarks-on-map

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