Note that there are some explanatory texts on larger screens.

plurals
  1. POgeocoding function works when called in initialized, but not in onclick script
    primarykey
    data
    text
    <p>I'm doing some geocoding using the google maps API. The user fill a form with some address, and when the submit button is clicked, a codeAddress() function is called, which is supposed to perform the geocoding, but it does not work. As a test, I hardcoded the address and call the codeAddress function when the document in an initialize(). When codeAddress is called when the page is ready, it works ok, but when it's called by the onclick script, it doesn't work (no errors returned by firebug!).</p> <p>Anybody can help? Thanks</p> <p>(you can paste the code in here: <a href="http://code.google.com/apis/ajax/playground/?exp=maps#map_simple" rel="nofollow noreferrer">http://code.google.com/apis/ajax/playground/?exp=maps#map_simple</a>, or change the google api key)</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml"&gt; &lt;head&gt; &lt;meta http-equiv="content-type" content="text/html; charset=utf-8"/&gt; &lt;title&gt;Google Maps API Sample&lt;/title&gt; &lt;script src="http://maps.google.com/maps?file=api&amp;amp;v=2&amp;amp;sensor=false&amp;amp;key=ABQIAAAA1XbMiDxx_BTCY2_FkPh06RRaGTYH6UMl8mADNa0YKuWNNa8VNxQEerTAUcfkyrr6OwBovxn7TDAH5Q"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; function initialize() { if (GBrowserIsCompatible()) { var map = new GMap2(document.getElementById("map_canvas")); map.setCenter(new GLatLng(37.4419, -122.1419), 13); codeAddress(); } } function codeAddress() { var geocoder = new GClientGeocoder(); var address = "paseo montjuic, 30, barcelona, spain"; geocoder.getLatLng( address, function(point) { if (point) { alert(point); } else { alert("Geocode was not successful"); } }); } &lt;/script&gt; &lt;/head&gt; &lt;body onload="initialize()" onunload="GUnload()" style="font-family: Arial;border: 0 none;"&gt; &lt;div id="map_canvas" style="width: 500px; height: 300px"&gt;&lt;/div&gt; &lt;form action="" method="POST"&gt; &lt;!-- stuff --&gt; &lt;input type="Submit" value="Submit" onclick="codeAddress();" /&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload