开发者

Adding Markers to a Google Map: WordPress & XML

I'm following this tutorial on placing markers on a Google Map using PHP and MySQL. I'm adapting it to work in a WordPress Shortcode plugin. I've built the map and pulled the lat longs from the database. I'm having problems figuring out how to get WordPress to output XML, (which will then be used by javascript to place the markers). This is a snippet of my plugin:

    $dom = new DOMDocument('1.0');
    $node = $dom->createElement('markers');
    $parnode = $dom->appendChild($node);

    $csf_data = $wpdb->get_results($wpdb->prepare("SELECT * FROM my_table"));             


    foreach($csf_data as $incident) {
        $node = $dom->createElemen开发者_运维知识库t('marker');
        $newnode =  $parnode->appendChild($node);
        $newnode->setAttribute("lat", $incident->latitude);
        $newnode->setAttribute("lng", $incident->longitude);
    }


    echo $dom->saveXML;

I'm not sure what I need to do to get this to work.

  • How do I tell if the XML was built? In the tutorial, it says call the PHP script in the browser. In my case, the PHP above is part of the main plugin file.

  • After, the XML is output, how do I load it? I don't have a url to point to? How do I output the XML to a URL? The function used to load the XML file, function downloadUrl(url,callback) takes a URL as a parameter.

Any suggestions?

Thank you.


I think you must deal with the problems one by one.

  • First make sure that you construct a single php page tha queries your mysql database ,pulls the records and echo's them in xml or json format(preferrably json).

  • Then make a javascript page that makes an ajax call to the url of the php page discussed above (with either javascript or jquery -preferrably jquery if you don't have javascript experience-) and after you get it working then put it in your plugin.That way you can ensure you have working code in all stages.

If you want more help please post some specific code example in let's say jsfiddle so we can examine it.

Cheers

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜