0

Ok, so I have a working (almost) geocoder built, that takes in an address or lat/lon combination, and suggests results see here:

$(this).autocomplete({

        source:function (request, response) {

            if (geocoder == null) {
                geocoder = new google.maps.Geocoder();
            }
            geocoder.geocode({'address':request.term }, function (results, status) {

                if (status == google.maps.GeocoderStatus.OK) {
                    var searchLoc = results[0].geometry.location;
                    var lat = results[0].geometry.location.lat();
                    var lng = results[0].geometry.location.lng();
                    var latlng = new google.maps.LatLng(lat, lng);
                    var bounds = results[0].geometry.bounds;

                    geocoder.geocode({'latLng':latlng}, function (results1, status1) {
                        if (status1 == google.maps.GeocoderStatus.OK) {
                            if (results1[1]) {
                                response($.map(results1, function (loc) {
                                    return {
                                        label:loc.formatted_address,
                                        lat:lat,
                                        lng:lng,
                                        value:loc.formatted_address,
                                        bounds:loc.geometry.bounds
                                    }
                                }));
                            }
                        }
                    });
                }
            });
        },

and 90% of the time it works smashingly. However, I am now noticing that occasionally the first item that it returns in the pop-down list is not clickable. I have set logs for the variable status and have noticed that occasionally it is ZERO_RESULT or QUERY_LIMIT_REACHED. In both of these instances, the list loads with values, and everything on the list is selectable except for the first one. Any ideas for possible solutions?

Alex Neigher
  • 887
  • 1
  • 10
  • 22

1 Answers1

0

It looks like there were instances where bounds was left out by the API, and thus being defined in my code as undefined. This was causing a javascript issue further down the code, and preventing a conditional from being met. It looks like this isn't even needed to frame the map properly, and i have solved my issue...

Alex Neigher
  • 887
  • 1
  • 10
  • 22