/    Sign up×
Community /Pin to ProfileBookmark

Why is Google maps Geocoder always responding back with OK

I’m attempting to validate my location input field against google’s map geocoder API. IF the address is valid save it to a hidden field if it’s invalid empty the hidden field. However, Geocoder is always responding back with ‘OK’ regardless of the input value. I’m not sure why or how to get this to work.
my code:

[code=html]<input class=”form-control” type=”text” id=”joblocation” placeholder=”Enter a Location (ie. Phoenix, AZ)” value=”<?php echo set_value(‘location’); ?>” name=”location” onchange=”doGeocode()” />[/code]

[CODE]
<script>

var input = document.getElementById(‘joblocation’);
var options = {
types: [‘(cities)’]
};

autocomplete = new google.maps.places.Autocomplete(input, options);
autocomplete.setComponentRestrictions({‘country’: [‘us’, ‘ca’, ‘au’, ‘ge’, ‘in’, ‘uy’]});

function doGeocode(){
var addr = document.getElementById(“joblocation”);
// Get geocoder instance
var geocoder = new google.maps.Geocoder();

// Geocode the address
geocoder.geocode({‘address’: addr.value}, function(results, status){
if (status === google.maps.GeocoderStatus.OK && results.length > 0) {

alert(“Valid Address”);
//do something

// show an error if it’s not
} else {
alert(“Invalid address”);
}
});
};

</script>[/CODE]

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @dottedquad spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...