Below is my script which is working fine.
In below script,in given line viewMap(40.671531,-73.963588); i am displaying the user current location.
Now i want to display multiple markers on map near by my current location. Can any one help me to draw multiple markers near by my current location.
<script type="text/javascript">
var map;
var marker;
var infowindow = new google.maps.InfoWindow();
var geocoder = new google.maps.Geocoder();
function initialize() {
var location = document.getElementById('pickadd');
var options = {
types: ['geocode'],
componentRestrictions: {country: "IND"}
};
var autocomplete = new google.maps.places.Autocomplete(location,options);
google.maps.event.addListener(autocomplete, 'place_changed', function () {
var place = autocomplete.getPlace();
document.getElementById('PoolLatitude').value = place.geometry.location.lat();
document.getElementById('PoolLongitude').value = place.geometry.location.lng();
viewMap(place.geometry.location.lat(),place.geometry.location.lng());
});
}
function viewMap(lat,lng){
var myLatlng = new google.maps.LatLng(lat,lng);
var myOptions = {
zoom: 14,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var MarkImage = new google.maps.MarkerImage("/img/mapicons/icon1.png");
var marker = new google.maps.Marker({
draggable: true,
icon: MarkImage,
position: myLatlng,
map: map,
title: "Your location"
});
var formatted_address = '<img src="/img/pick_up.png" id="pick" class="pickupmap" alt="PickUp here">';
infowindow.setContent(formatted_address);
infowindow.open(map, marker);
google.maps.event.addListener(marker, 'dragend', function (event) {
geocodePosition(marker.getPosition());
document.getElementById("PoolLatitude").value = this.getPosition().lat();
document.getElementById("PoolLongitude").value = this.getPosition().lng();
});
function geocodePosition(pos) {
var geocoder= new google.maps.Geocoder();
geocoder.geocode({
latLng: pos
}, function(responses) {
if (responses && responses.length > 0) {
document.getElementById("PoolLocation").value = responses[0].formatted_address;
}
});
}
}
viewMap(40.671531,-73.963588);
google.maps.event.addDomListener(window, 'load', initialize);
</script>