Adalat  Khan

Adalat Khan

  • 602
  • 1.5k
  • 870.5k

Autocomplete Address using Google API

Mar 18 2019 12:34 PM
I implemented Google Places Autocomplete TextBox with Place changed event but its not working in MVC Core framework. Please find out mistakes why the following code is not working in MVC Core Framework:
 
HTML Code:
 
<input type="text" id="txtFullAddress" />
 
//JavaScript Code
  1. <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places"></script>  
  2. <script type="text/javascript">  
  3. google.maps.event.addDomListener(window, 'load'function () {  
  4. var inputAddressField = document.getElementById("txtFullAddress");  
  5. var places = new google.maps.places.Autocomplete(inputAddressField);  
  6. google.maps.event.addListener(places, 'place_changed'function () {  
  7. var place = places.getPlace();  
  8. var address = place.formatted_address;  
  9. var latitude = place.geometry.location.lat();  
  10. var longitude = place.geometry.location.lng();  
  11. var mesg = "Address: " + address;  
  12. mesg += "\nLatitude: " + latitude;  
  13. mesg += "\nLongitude: " + longitude;  
  14. alert(mesg);  
  15. });  
  16. });  
  17. </script>  

Answers (2)