Я хочу показать правильное местоположение на карте Google, динамически выбирая широту и долготу адреса, вставляя из текстового поля - PullRequest
0 голосов
/ 16 сентября 2009

Мне был создан код для местоположения, указанного пользователем при вводе через текстовое поле (например, http://maps.google.com/local/add/lookup?welcome=false&hl=en-US&gl=US), код приведен ниже.

Я совершенно новичок в этой технологии, пожалуйста, помогите мне как лучше.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=abcdefg&sensor=true_or_false"
            type="text/javascript"></script>

<script type="text/javascript">

function geocoder(){

var place =  document.getElementById("textarea").value;

geocoder = new GClientGeocoder();
geocoder.getLatLng(place, function(point) {
    if (!point) {
        alert(place + " not found");
    } else {
        var info = "<h3>"+place+"</h3>Latitude: "+point.y+"  Longitude:"+point.x;
        var map = new GMap2(document.getElementById("map_canvas"));
        var x=map.setCenter(new GLatLng(point.y, point.x), 13);
        map.setUIToDefault();       
      var marker = new GMarker(point);
     map.addOverlay(marker);
        marker.openInfoWindowHtml(x);
    }
});}
</script>





</head>

<body>


<table width="347" border="1" align="right">
  <tr>
    <td width="168">&nbsp;</td>
    <td width="163">&nbsp;</td>
  </tr>
  <tr>
    <td height="45"><div align="right">Address : </div></td>
    <td><form id="form1" name="form1" method="post" action="">
      <label>
      <textarea name="textarea" id="textarea"></textarea>
      </label>
    </form>
    </td>
  </tr>
  <tr>
    <td><form id="form2" name="form2" method="post" action="">
      <label>
        <input name="Button" type="Button" id="Button" value="Submit" onClick="geocoder()" onunload="GUnload()"/>
        </label>
    </form>
    </td>
    <td>&nbsp;</td>
  </tr>
</table>
 <div id="map_canvas" style="width: 500px; height: 300px"></div>


</body>
</html>

1 Ответ

0 голосов
/ 08 октября 2009

map.setCenter () ничего не возвращает, и нет смысла разбивать «точечный» GLatLng, чтобы немедленно склеить его, чтобы вы могли изменить эту строку

  var x=map.setCenter(new GLatLng(point.y, point.x), 13);

до

  map.setCenter(point, 13);

И изменить это

  marker.openInfoWindowHtml(x);

до

  marker.openInfoWindowHtml(point.toUrlValue(5));

Вызов .toUrlValue (5) просто округляет значения до 5 десятичных знаков. Без этого вы вполне можете получить до 14 десятичных знаков, и «точка» уже содержит закрытие функции на той копии GLatLng, которую вы хотите, поэтому вам не нужен «x».

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...