<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style type="text/css">
#txtPlaces
{
background-color: #fff;
padding: 0 11px 0 13px;
width: 400px;
font-family: Arial;
font-size: 12pt;
font-weight: 300;
border: 1px solid transparent;
border-radius: 2px;
box-sizing: border-box;
-moz-box-sizing: border-box;
height: 30px;
outline: none;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}
#dvPlaces
{
color: #fff;
background-color: #0090CB;
margin-top: 10px;
border: 1px solid transparent;
border-radius: 2px;
box-sizing: border-box;
-moz-box-sizing: border-box;
padding: 5px;
outline: none;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
font-size: 10pt;
}
</style>
</head>
<body>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=<API Key>&libraries=places"></script>
<script type="text/javascript">
google.maps.event.addDomListener(window, 'load', function () {
//Load the Google Map.
var mumbai = new google.maps.LatLng(18.9750, 72.8258);
var mapOptions = {
zoom: 7,
center: mumbai
};
var map = new google.maps.Map(document.getElementById('dvMap'), mapOptions);
//Load the Places AutoComplete TextBox.
var places = new google.maps.places.Autocomplete(document.getElementById('txtPlaces'));
places.bindTo('bounds', map);
//Place the Places AutoComplete TextBox on the Google Map.
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(document.getElementById("dvPlaces"));
//Initialize the marker.
var marker = new google.maps.Marker({
position: mumbai,
map: map
});
marker.setVisible(false);
//Assign the Place_Changed event handler to the Places AutoComplete TextBox.
google.maps.event.addListener(places, 'place_changed', function () {
//Remove previous marker.
marker.setMap(null);
//Plot the marker for the Address Location on the Google Map.
var place = places.getPlace();
if (place.geometry) {
marker = new google.maps.Marker({
position: place.geometry.location,
map: map
});
map.setCenter(place.geometry.location);
//Display Info Window for the Address Location.
var infoWindow = new google.maps.InfoWindow();
infoWindow.setContent("<div style = 'width:100px;min-height:10px'>" + place.name + "</div>");
infoWindow.open(map, marker);
}
});
});
</script>
<div id="dvPlaces">
<input type="text" id="txtPlaces" style="width: 200px" />
</div>
<div id="dvMap" style="width: 400px; height: 400px"></div>
</body>
</html>