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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Distance Related Search Google API

Status
Not open for further replies.

wilberforce2

IS-IT--Management
Jan 8, 2007
36
GB
Hello

I am new to ASP.net 2.0 and I am having some problems creating a distance related search in a directory.

I am using the following code to get Latitude and longitude data from google maps from a postcode a user types in to perform a search. The problem I am having is that to use the showAddress function I must call it with return false but this prevents the form posting and the search being imitated. Any ideas in how I can solve this issue. I have looked everywhere on the web and cannot find any examples. I am using Visual Web Studio Express Edition. The database already has the Latitude and longitude details for each entry. I can post the full code if it’s required.

Thanks

Code:
   <script type="text/javascript">
    var map = null;
    var geocoder = null;

    function initialize() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
        geocoder = new GClientGeocoder();
      }
    }

  function showAddress(address) {
  
      if (geocoder) {
      alert("GeoCode")
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert(address + " not found");
            } else {
              map.setCenter(point, 13);
              alert(point.y)
              //document.getElementById("DetailsView1_LatTextbox").value = point.y
              //document.getElementById("DetailsView1_LonTextbox").value = point.x
            }
          }
        );
      }
    }
       
    </script>

OnClientClick="showAddress(document.getElementById('TextBox1').value); return false" />
 
you're attempting to mix client and server code. if you don't/can't use a full postback then you have 2 options:
1. use an ms ajax updatepanel to create a ajax call.
2. create a web serivce which executes the search and returns the results in xml/json format. parse on client and display.

depending on how your page functions may dictate if either option is viable.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top