简体   繁体   中英

Implementing Google Maps geocoder in MVC

I have struggled over the past few days to implement the Google Maps geocoder onto a view. Is there any way of achieving a result similar to this? https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-addressform

From what I saw and deconstructed, these are the basic elements for just the autocomplete search but where am I going wrong?

<input id="Address" placeholder="Enter your address" type="text">

@section scripts{
    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCGp6FlcyAD0pxQ9DJr4pNW2nwfTYaCFTg&libraries=places"></script>
    <script type="text/javascript">
        var input = document.getElementById('Address');
        var places = new google.maps.places.Autocomplete(input);
    </script>
}

Also, if there are better suggestions for an autocomplete geocoder apart from Google's implementation, I would very much like to know.

For anyone that has this same problem, there seems to be an issue in how Visual Studio is rendering the entire project and thus ignores the autocomplete feature altogether for some reason during the emulation.

You can still deploy your site and the feature will work as intended

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM