2009-09-16 3 views
0

J'ai été créé le code pour l'emplacement spécifiez par l'entrée d'utilisateur par la zone de texte (par exemple http://maps.google.com/local/add/lookup?welcome=false&hl=en-US&gl=US) le code est donné ci-dessous .Je souhaite afficher l'emplacement correct dans google map en récupérant dynamiquement Latitude & Longitude d'adresse en insérant à partir de la zone de texte

Je suis totalement nouveau pour cette technologie, aidez-moi le mieux possible.

<!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> 

Répondre

0

map.setCenter() ne retourne rien, et il n'y a pas de fractionnement de point, le « point » GLatLng afin de coller immédiatement de nouveau ensemble afin que vous puissiez changer cette ligne

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

à

map.setCenter(point, 13); 

Et changer cette

marker.openInfoWindowHtml(x); 

à

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

Le .toUrlValue (5) appel arrondit simplement les valeurs à 5 décimales. Sans cela, vous pouvez obtenir jusqu'à 14 décimales, et "point" détient déjà la fonction de fermeture sur une copie du GLatLng que vous voulez, donc vous n'avez pas besoin de "x".

Questions connexes