I have a code in maps JS api. I have 2 query search , one for finding near pharmacy, and other for hospitals. I want to label the returning markers with F for pharmacy and H for hospitals. How do I make this separation? And how can I put in query to search for hospitals and pharmacies? I tried many combinations but it return only hospital or pharmacies.
<script
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyD6uiXpiTDkhGcAG9X4G8vm1rF2eXQzXMI&callback=initialize&libraries=places&v=weekly"
defer></script>
let map;
let service;
let infowindow;
function initialize() {
infowindow = new google.maps.InfoWindow();
//Map options
var options = {
center: userPosition,
zoom: 14,
// disableDefaultUI: true,
}
//New map
map = new
google.maps.Map(document.getElementById("map"), options);
var request = {
location: userPosition,
radius: '2000',
query: "hospital, pharmacy",
// query: 'spital',
};
service = new google.maps.places.PlacesService(map);
service.textSearch(request, callback);;
function addUserLocationMarker() {
marker = new google.maps.Marker({
map,
draggable: true,
animation: google.maps.Animation.DROP,
position: userPosition,
icon: "http://maps.google.com/mapfiles/kml/pushpin/grn-pushpin.png"
});
marker.addListener("click", toggleBounce);
var infoWindow = new google.maps.InfoWindow({
content: "<h3>Locatia mea ! </h3>"
});
marker.addListener('click', function () {
infoWindow.open(map, marker);
});
}
addUserLocationMarker();
}
let neighborhoods = [];
function callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
var place = results[i];
// createMarker(results[i]);
drop(results);
}
}
}
let markers = [];
function drop(neighborhoods) {
clearMarkers();
for (let i = 0; i < neighborhoods.length; i++) {
addMarkerWithTimeout(neighborhoods[i], i * 200);
}
}
function addMarkerWithTimeout(place, timeout) {
window.setTimeout(() => {
var marker = new google.maps.Marker({
map,
position: place.geometry.location,
animation: google.maps.Animation.DROP,
});
google.maps.event.addListener(marker, "click", () => {
infowindow.setContent('<h2>' + place.name + '</h2>');
infowindow.open(map, marker);
}),
marker.addListener("click", toggleBounce);
markers.push(marker);
}, timeout);
}
function clearMarkers() {
for (let i = 0; i < markers.length; i++) {
markers[i].setMap(null);
}
markers = [];
}
function toggleBounce() {
if (marker.getAnimation() !== null) {
marker.setAnimation(null);
} else {
marker.setAnimation(google.maps.Animation.BOUNCE);
}
}
function ipLookup() {
$.get('https://api.userinfo.io/userinfos', function (r) {
showUserDetails(r.position.latitude, r.position.longitude, r);
});
}
</script>
