在Google Maps中使用PHP / MySQL [英] Using PHP/MySQL with Google Maps

查看:92
本文介绍了在Google Maps中使用PHP / MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新2 :所以我从来没有在萤火虫中使用调试功能,但我只是看了脚本部分,然后我得到了这个,现在我会尝试解决这个问题。


无法加载源代码:
http://localhost/googleMap/phpsqlajax_genxml.php




我在
下面跟着本教程 http://code.google.com/intl/zh-CN/apis/maps/articles/phpsqlajax_v3.html#outputxml



我遇到了麻烦,接近结束时,我我希望别人在这里有
这个工作,并可以帮助我发现我的问题。简单地说,本教程有4
的步骤。
$ b


  • 创建表格

  • 填充表格

  • 用PHP输出XML

  • 创建地图
    b

    我成功完成了所有步骤,但输出的xml
    没有被我创建的google地图读取。这些文件都在同一个
    目录中,而且我没有更改
    教程中的任何文件名。本教程有一个步骤来测试名为
    phpsqlajax_genxml.php的php文件是否正在输出xml,并且我成功测试了
    它并且它是。



    问题是地图没有渲染我在
    数据库中的项目,应该将它转换为xml供地图阅读。



    任何帮助,或指引我正确的方向将是
    $赞赏。



    更新1 :我意识到我没有有任何代码在这里显示,只有3个文件,所以我不知道哪个将是最好的使用。我有一个问题可以帮助我解决问题。



    在本教程的xml输出部分,我也会问到


    从浏览器
    调用此PHP脚本以确保它生成有效的XML。
    如果您怀疑连接到数据库的
    存在问题,那么如果您删除
    文件中用于设置
    的行,则
    可能更易于调试头文件到text / xml内容类型
    ,因为这通常会导致浏览器到
    尝试解析XML,并且可能使
    难以看到您的调试
    消息。


    这是phpsqlajax_dbinfo.php文件

     <?php 
    $ username =root;
    $ password =root;
    $ database =root-googleMap;
    ?>

    这是生成xml的代码,是一个xml文档实际制作后可以打开,还是临时转换?如果是这样,我怎么做上面的步骤来测试,我真的不明白。

     <?php 
    require ( phpsqlajax_dbinfo.php);

    //启动XML文件,创建父节点
    $ doc = domxml_new_doc(1.0);
    $ node = $ doc-> create_element(markers);
    $ parnode = $ doc-> append_child($ node);

    //打开一个到mySQL服务器的连接
    $ connection = mysql_connect(localhost,$ username,$ password);
    if(!$ connection){
    die('Not connected:'。mysql_error());
    }

    //设置活动的mySQL数据库
    $ db_selected = mysql_select_db($ database,$ connection);
    if(!$ db_selected){
    die('不能使用db:'。mysql_error());
    }

    //选择标记表中的所有行
    $ query =SELECT * FROM markers WHERE 1;
    $ result = mysql_query($ query);
    if(!$ result){
    die('Invalid query:'。mysql_error());
    }

    header(Content-type:text / xml);

    //遍历行,为每个
    添加XML节点,同时($ row = @mysql_fetch_assoc($ result)){
    //添加到XML DOCUMENT节点
    $ node = $ doc-> create_element(marker);
    $ newnode = $ parnode-> append_child($ node);

    $ newnode-> set_attribute(name,$ row ['name']);
    $ newnode-> set_attribute(address,$ row ['address']);
    $ newnode-> set_attribute(lat,$ row ['lat']);
    $ newnode-> set_attribute(lng,$ row ['lng']);
    $ newnode-> set_attribute(type,$ row ['type']);
    }

    $ xmlfile = $ doc-> dump_mem();
    echo $ xmlfile;

    ?>


    解决方案

    我假设(并希望)不再使用PHP 4,并且这是问题的根源,与DOM XML操作相关的功能已被替换为DOMDocument类,它具有不同的方法名称。



    <因此,我已经重构了您的代码以兼容PHP 5:

     <?php 
    require ( phpsqlajax_dbinfo.php);

    //启动XML文件,创建父节点
    $ doc = new DOMDocument(1.0);
    $ node = $ doc-> createElement(markers);
    $ parnode = $ doc-> appendChild($ node);

    //打开一个到mySQL服务器的连接
    $ connection = mysql_connect(localhost,$ username,$ password);
    if(!$ connection){
    die('Not connected:'。mysql_error());
    }

    //设置活动的mySQL数据库
    $ db_selected = mysql_select_db($ database,$ connection);
    if(!$ db_selected){
    die('不能使用db:'。mysql_error());
    }

    //选择标记表中的所有行
    $ query =SELECT * FROM markers WHERE 1;
    $ result = mysql_query($ query);
    if(!$ result){
    die('Invalid query:'。mysql_error());
    }

    header(Content-type:text / xml);

    //遍历行,为每个
    添加XML节点,同时($ row = @mysql_fetch_assoc($ result)){
    //添加到XML DOCUMENT节点
    $ node = $ doc-> createElement(marker);
    $ newnode = $ parnode-> appendChild($ node);

    $ newnode-> set_attribute(name,$ row ['name']);
    $ newnode-> set_attribute(address,$ row ['address']);
    $ newnode-> set_attribute(lat,$ row ['lat']);
    $ newnode-> set_attribute(lng,$ row ['lng']);
    $ newnode-> set_attribute(type,$ row ['type']);
    }

    echo $ doc-> saveXML();

    ?>


    Update 2: So I never have used the debug function in firebug, but I just looked at the script section and I get this, now I will try and figure this out.

    Failed to load source for: http://localhost/googleMap/phpsqlajax_genxml.php

    Hiya,

    I followed this tutorial below http://code.google.com/apis/maps/articles/phpsqlajax_v3.html#outputxml

    I ran into trouble, near then end, I am hoping someone else here has got this working and can help me discover my problem. Simply there are 4 steps to this tutorial

    • Creating the Table
    • Populating the Table
    • Outputting XML with PHP
    • Creating the Map

    I successfully have completed all the steps, however the outputted xml isn't read by the google map I created. The files are all on the same directory, and I didn't change any of the file names from the tutorial. The tutorial has a step to test if the php file called phpsqlajax_genxml.php is outputting the xml and I successfully tested it and it was.

    The problem is that the map isn't rendering the items I have in the database, that should be converted to xml for the map to read.

    Any help, or pointing me in the right direction would be much appreciated.

    UPDATE 1: I realize I don't have any code to show here, there are just 3 files so I am not sure which will be of the best use. I Have a question that might help my issue though.

    In the xml output part of the tutorial I am asked too

    Call this PHP script from the browser to make sure it's producing valid XML. If you suspect there's a problem with connecting to your database, you may find it easier to debug if you remove the line in the file that sets the header to the text/xml content type, as that usually causes your browser to try to parse XML and may make it difficult to see your debugging messages.

    This is the phpsqlajax_dbinfo.php file

    <?php
    $username="root";
    $password="root";
    $database="root-googleMap";
    ?>
    

    This is the code for the generate xml, Is a xml document actually made after and can I open in, or is it temporary conversion. If so How do i do the step above to test, I dont really understand.

    <?php
    require("phpsqlajax_dbinfo.php");
    
    // Start XML file, create parent node
    $doc = domxml_new_doc("1.0");
    $node = $doc->create_element("markers");
    $parnode = $doc->append_child($node);
    
    // Opens a connection to a mySQL server
    $connection=mysql_connect (localhost, $username, $password);
    if (!$connection) {
      die('Not connected : ' . mysql_error());
    }
    
    // Set the active mySQL database
    $db_selected = mysql_select_db($database, $connection);
    if (!$db_selected) {
      die ('Can\'t use db : ' . mysql_error());
    }
    
    // Select all the rows in the markers table
    $query = "SELECT * FROM markers WHERE 1";
    $result = mysql_query($query);
    if (!$result) {
      die('Invalid query: ' . mysql_error());
    }
    
    header("Content-type: text/xml");
    
    // Iterate through the rows, adding XML nodes for each
    while ($row = @mysql_fetch_assoc($result)){
      // ADD TO XML DOCUMENT NODE
      $node = $doc->create_element("marker");
      $newnode = $parnode->append_child($node);
    
      $newnode->set_attribute("name", $row['name']);
      $newnode->set_attribute("address", $row['address']);
      $newnode->set_attribute("lat", $row['lat']);
      $newnode->set_attribute("lng", $row['lng']);
      $newnode->set_attribute("type", $row['type']);
    }
    
    $xmlfile = $doc->dump_mem();
    echo $xmlfile;
    
    ?>
    

    解决方案

    I'm assuming (and hoping) you're not using PHP 4 anymore and that this is the source of your problem, the functions relating to the DOM XML manipulation have been replaced with the DOMDocument class, which has different method names.

    As such, I have refactored your code to be compatible with PHP 5:

    <?php
    require("phpsqlajax_dbinfo.php");
    
    // Start XML file, create parent node
    $doc = new DOMDocument("1.0");
    $node = $doc->createElement("markers");
    $parnode = $doc->appendChild($node);
    
    // Opens a connection to a mySQL server
    $connection=mysql_connect (localhost, $username, $password);
    if (!$connection) {
      die('Not connected : ' . mysql_error());
    }
    
    // Set the active mySQL database
    $db_selected = mysql_select_db($database, $connection);
    if (!$db_selected) {
      die ('Can\'t use db : ' . mysql_error());
    }
    
    // Select all the rows in the markers table
    $query = "SELECT * FROM markers WHERE 1";
    $result = mysql_query($query);
    if (!$result) {
      die('Invalid query: ' . mysql_error());
    }
    
    header("Content-type: text/xml");
    
    // Iterate through the rows, adding XML nodes for each
    while ($row = @mysql_fetch_assoc($result)){
      // ADD TO XML DOCUMENT NODE
      $node = $doc->createElement("marker");
      $newnode = $parnode->appendChild($node);
    
      $newnode->set_attribute("name", $row['name']);
      $newnode->set_attribute("address", $row['address']);
      $newnode->set_attribute("lat", $row['lat']);
      $newnode->set_attribute("lng", $row['lng']);
      $newnode->set_attribute("type", $row['type']);
    }
    
    echo $doc->saveXML();
    
    ?>
    

    这篇关于在Google Maps中使用PHP / MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆