-2

可能重复:
尝试将 Google Places API 与 JQuery 的 getJSON 函数一起使用

我正在尝试将元素读入表格。

我正在将元素放入文本字​​段。相反,我想在表格中显示..

下面是代码

   function createMarker(place) {
        //var placeLoc = place.geometry.location;
        var request = {
          reference: place.reference
        };

        service = new google.maps.places.PlacesService(map);
        service.getDetails(request, callback);
        service.getDetails(request, function(details, status) {//alert("address  "+details.formatted_address);

        document.getElementById('box1').value=details.formatted_address;
        document.getElementById('box2').value=details.name;
        document.getElementById('box3').value=details.international_phone_number;

    });

  }
   google.maps.event.addDomListener(window, 'load', initialize);

  </script>
  </head>
  <body>

  <input type="text" id="box1" size="20"/>
  <input type="text" id="box2" size="50"/>
  <input type="text" id="box3" size="20"/>
    <div id="map"></div>
    <div id="text">

</body>
</html>
4

1 回答 1

1
<html>
<head>
<style>
table {
  border-collapse: collapse;
}
table td, table th {
  border: 1px solid black;
}
table tr:first-child th {
  border-top: 0;
}
table tr:last-child td {
  border-bottom: 0;
}
table tr td:first-child,
table tr th:first-child {
  border-left: 0;
}
table tr td:last-child,
table tr th:last-child {
  border-right: 0;
}
</style>
<script>
  function createMarker(place) {
    //var placeLoc = place.geometry.location;
     var request = {
     reference: place.reference
    };

    service = new google.maps.places.PlacesService(map);
    service.getDetails(request, function(details, status) {//alert("address  "+details.formatted_address);

      document.getElementById('box1').innerHTML=details.formatted_address;
      document.getElementById('box2').innerHTML=details.name;
      document.getElementById('box3').innerHTML=details.international_phone_number;    
   });

  }
  google.maps.event.addDomListener(window, 'load', initialize);

  </script>
  </head>
  <body>

  <table>
  <tr><td>Address:</td><td id="box1"></td></tr>
  <tr><td>Name:</td><td id="box2"></td>
  <tr><td>Phone:</td><td id="box3"></td>
  </tr>
  </table>

   <div id="map"></div>
   <div id="text">

</body>
</html>
于 2012-09-26T09:20:02.017 回答