views:

143

answers:

1

I have been created code for the location specify by user entry through text box(e.g. http://maps.google.com/local/add/lookup?welcome=false&hl=en-US&gl=US ) the code is given below.

I'm totally new for this technology plz help me as ur best.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<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;amp;v=2&amp;amp;key=abcdefg&amp;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>
A: 

map.setCenter() doesn't return anything, and there's no point splitting the "point" GLatLng in order to immediately glue it back together so you can change this line

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

to

  map.setCenter(point, 13);

And change this

  marker.openInfoWindowHtml(x);

to

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

The .toUrlValue(5) call simply rounds the values to 5 decimal places. Without it you may well get up to 14 decimal places, and "point" already holds function closure on a copy of the GLatLng you want, so you don't need "x".

Mike Williams