logo
We have finished migration to the new data center successfully and are working out some minor issues within the site's code. If you experience any difficulties or have any questions please email us at [email protected].
Ask your WordPress questions! Pay money and get answers fast! (more info)

timDesain Nanang

Website



Written in response to Field for ZIP and CITY autocomplete:

since the question has expired.

try the following code instead:

add_action('wp_footer', 'wpq11327_wp_footer', 999);
function wpq11327_wp_footer() {
?>
<script type="text/javascript">
jQuery("body").on("focus", "#cp_city_zipcode", function(){
geolocate();
});
</script>

<script type="text/javascript">
var autocomplete;
var input = document.getElementById('cp_city_zipcode');
var options = {
componentRestrictions: {'country':'ch'},
types: ['(cities)'] // (cities)
};

function initAutocomplete() {
// Create the autocomplete object, restricting the search to geographical location types.
autocomplete = new google.maps.places.Autocomplete(input,options);
}

// [START region_geolocation]
function geolocate() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var geolocation = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
var circle = new google.maps.Circle({
center: geolocation,
radius: position.coords.accuracy
});
autocomplete.setBounds(circle.getBounds());
});
}
}
// [END region_geolocation]
</script>

<script src="https://maps.googleapis.com/maps/api/js?signed_in=true&libraries=places&callback=initAutocomplete" async defer></script>
<?php
}



Updated: 08/18/15 3:33pm


Upvote / Downvote

3 groups of people are allowed to vote for discourse:

All votes are public.

You are not allowed to vote: