Hi Ross,

Many thanks for the advice, and all makes perfect sense.  My current problem
is most likely extremely trivial and a slight error in my syntax, but I'm
clouded by the new usage of the Google Map API's, so I need to make sure.

Here's my code:
___________________________________________________________
<head>
    <script src="
http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=ABQIAAAA04liSyPUEnzZyfxqwGgrZxQWhJ__TbHlqZWCEG2UZp394QQIBhTks2zomwmJx-Bee4BVk5Kf5v-hwg";
type="text/javascript"></script>
    <script type="text/javascript">
<script src="
http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=ABQIAAAA04liSyPUEnzZyfxqwGgrZxQWhJ__TbHlqZWCEG2UZp394QQIBhTks2zomwmJx-Bee4BVk5Kf5v-hwg";
type="text/javascript"></script>
    <script type="text/javascript">
 function getLength(from, to) {
  alert("function triggered");
  geocoder = new GClientGeocoder();

        geocoder.getLatLng(from,function(from_gl) {
   if (!from_gl) {
                   alert(from + " not found");
   }
   else {
    geocoder.getLatLng(to,function(to_gl) {
     if (!to_gl) {
      alert(to + " not found");
     }
     else {
      alert(to_gl.distanceFrom(from_gl));
     }
    });
   }
  });
 }

     function basicTest(){
      alert("basic test");
     }
</script>
  <body>
   <div id="distance"></div>
   <div id="map"></div>
   <a href="#" onClick="getLength("Sydney,NSW","Coogee,NSW");">Click
me</a><BR>
   <a href="#" onClick="basicTest();">Click me</a><BR>
  </body>
</html>
___________________________________________________________

The "basicTest" was done to double check I had paired off the {} brackets -
which originally it wasn't.  I'm really scratching my head though as I don't
even get the alert of the "getLength()" to indicate it's entered the
function - for the life of me, I can't find out the reason this is though...

Anyone?

Cheers,
Jesse.
On Mon, Jun 8, 2009 at 6:38 PM, Rossko <[email protected]> wrote:

>
> GLatLng is the API's basic location object, it's a 'thing' not a
> function.  It does come with built-in methods to operate on the
> location, such as .distanceFrom()
>
> geocoder.getLatLng() is method that returns you some data, that data
> is ready-structured as a GLatLng object for you by the API.
> As a GLatLng object, it has the distanceFrom() method built-in.
>
> Note that return of the data is asynchronous because of the round-trip
> to Google and back.
>   http://econym.org.uk/gmap/async.htm
> Note that if you have only one geocoder object, and start re-using it
> before the previous result comes back, things will go wrong.
>
> Some structure like this should work (untested) -
>         geocoder.getLatLng(from,function(from_gl) {
>                if (!from_gl) {
>                        alert(from + " not found");
>                    }
>                    else {
>                                geocoder.getLatLng(to,function(to_gl)
> {
>                                       if (!to_gl) {
>                                              alert(to + " not
> found");
>                                       }
>                                       else {
>                                              alert(to_gl.distanceFrom
> (from_gl));
>                                       }
>                               }
>                }
>      }
>
>
> As soon as you do more than one geocode at a time, you may run into
> the issues described here -
>   http://econym.org.uk/gmap/geomulti.htm
>
> Error checking any geocode request is probably a good idea
>  http://econym.org.uk/gmap/geo.htm
> but that would preclude simple use of geocoder.getLatLng
>
> cheers, Ross K
>  >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/Google-Maps-API?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to