dstk51319 2013-07-02 19:40
浏览 37
已采纳

AJAX / PHP:谷歌地图从我的代码中检索数据的问题

I am currently following this guide at Google developers.

https://developers.google.com/maps/articles/phpsqlajax_v3?hl=en-EN#createmap

I am adding a map on my website with geocoded entries. Each entry into the table is a business. Each entry/business currently has a field/column for

(name, address, lat, lng, type, url)

Screenshot Here http://postimg.org/image/3z8kcwq4b/

I was able to add the url field and it be displayed properly on the map markers. I need to be able to also add two more fields. 1 for 'phonenumber' and one for 'description.

the purpose of the above entries into the database is that when they click a marker on the map of an entry/business it will display information about that business. I can't get it to show this information when clicked. The code that I believe to be relevant to my issue is below.

here is the code I currently have.

Main Page:

  var name = markers[i].getAttribute("name");
  var address = markers[i].getAttribute("address");
  var url = markers[i].getAttribute("url");
  var type = markers[i].getAttribute("type");
  var point = new google.maps.LatLng(
      parseFloat(markers[i].getAttribute("lat")),
      parseFloat(markers[i].getAttribute("lng")));
  var html = '<a href="' + url + '">' + name + '</a> <br/>' + address + ' <br/>' ;

phpsqlajax_genxml2.php

  echo 'name="' . parseToXML($row['name']) . '" ';
  echo 'address="' . parseToXML($row['address']) . '" ';
  echo 'lat="' . $row['lat'] . '" ';
  echo 'lng="' . $row['lng'] . '" ';
  echo 'type="' . $row['type'] . '" ';
  echo 'url="' . $row['url'] . '" ';
  echo '/>';

I need to be able to add more info into the database so i can make the map call it. I would like for it to display a phone number and description when they click the map marker for that business.

(the above code pulls data from the tables on the database and displays the url of the business, the name of it, it's long/lat-geocoded, and it's address.)

I have been able to completely add this into my site except for this. Last thing i'm stuck on.

  • 写回答

1条回答 默认 最新

  • dongyan9950 2013-07-02 20:24
    关注

    I was able to ffix this issue like this

      var name = markers[i].getAttribute("name");
      var address = markers[i].getAttribute("address");
      var url = markers[i].getAttribute("url");
      var type = markers[i].getAttribute("type");
      var phone = markers[i].getAttribute("phone");
      var desc = markers[i].getAttribute("desc");
      var point = new google.maps.LatLng(
          parseFloat(markers[i].getAttribute("lat")),
          parseFloat(markers[i].getAttribute("lng")));
      var html = '<a href="' + url + '">' + name + '</a> <br/>' + address + '<br />Phone Number: ' + phone + '<br />' + desc + '<br />';
    

      echo 'name="' . parseToXML($row['name']) . '" ';
      echo 'address="' . parseToXML($row['address']) . '" ';
      echo 'lat="' . $row['lat'] . '" ';
      echo 'lng="' . $row['lng'] . '" ';
      echo 'type="' . $row['type'] . '" ';
      echo 'phone="' . $row['phone'] . '" ';
      echo 'desc="' . $row['desc'] . '" ';
      echo 'url="' . $row['url'] . '" ';
      echo '/>';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答