I'm trying to use the jquery library geocomplete to autocomplete a google address, and write to some hidden fields variables like the long, lat, location_type. It works for lat,lng which get written out, but I'm pulling my hairs to get the location type. Here's what I've tried:
#theJS
$(function(){
$("#id_address").geocomplete()
.bind("geocode:result", function(event, result){
$.log(result.formatted_address);
$("input#id_lat").val(result.geometry.location.lat());
$("input#id_lng").val(result.geometry.location.lng());
$("input#id_location_type").val(result.geometry.location_type());
})
});
#the HTML forms
<input id="id_lng" name="lng" type="hidden" />
<input id="id_lat" name="lat" type="hidden" />
<input id="id_location_type" name="location_type" type="text" />
<input type="text" name="address" id="id_address" />
To troubleshoot the results, I tried $("input#id_location_type").val(result.geometry);
and it does write to the location_type input box [object Object]
, but as soon as I extend it to result.geometry.location_type
or result.geometry.location_type()
I get nothing.
Any tips appreciated. (here's a jsfiddle to clarify what I'm trying to to)