Search code examples
javascriptmodel-view-controllerautocompletegeocodinggoogle-geocoder

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.


Solution

  • 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