Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript Google API

Status
Not open for further replies.

wilberforce2

IS-IT--Management
Jan 8, 2007
36
GB
I was wondering if someone could tell me why this tutorial is did from
It's just what I am looking for to complete a project I am working on but cannot get it to work I am not getting any errors it just fails to work. I am hoping that an expert will be able to see the error.

Code:
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]

<script runat="server">

</script>

<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] >
<head runat="server">
    <title>Test Google Goecode</title>
    <script src="[URL unfurl="true"]http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAdgQay5Vsf5PsEiFa2agefBT2yXp_ZAY8_ufC3CFXhHIE1NvwkxROjC-8ITWm-zgzl_cMNuItxRV-MA"[/URL] type="text/javascript"></script>
    <script src="[URL unfurl="true"]http://www.google.com/uds/api?file=uds.js&v=1.0&key=ABQIAAAAdgQay5Vsf5PsEiFa2agefBT2yXp_ZAY8_ufC3CFXhHIE1NvwkxROjC-8ITWm-zgzl_cMNuItxRV-MA"[/URL]
type="text/javascript"></script>
    
    <script language=javascript type="text/javascript">
    
    var localSearch = new GlocalSearch();

    function usePointFromPostcode(postcode, callbackFunction) {
    alert ("Function Called " + postcode)
    localSearch.setSearchCompleteCallback(null, 
    function() {
      
      if (localSearch.results[0]) {    
        var resultLat = localSearch.results[0].lat;
        var resultLng = localSearch.results[0].lng;
        var point = new GLatLng(resultLat,resultLng);
        callbackFunction(point);
      }else{
        alert("Postcode not found!");
      }
    });  
    
  localSearch.execute(postcode + ", UK");
}

    </script>    
    
</head>
<body>

    <form id="form1">
        &nbsp;<input type=text id="postcode" value="GL1 1HX"/>
       <input type="submit" value="Do whatever" onclick="javascript:usePointFromPostcode(document.getElementById('postcode').value, function (point) {alert('Latitude: ' + point.lat() + '\nLongitude: ' + point.lng());})" />
    </form>
</body>
</html>
 
Ok

I have got it working it was because it was in a form and the submit was causing problems. Now the million dollar question is why?

Any advice would be great.
 
When you click on a submit button, the form is submitted to the page on the server and any Javascript on the page that's called is lost then.

You might trying calling the function in the form's onsubmit event handler and have your function return true or false to that.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top