Last active
August 25, 2017 07:09
-
-
Save Guri-ksolves/8f7ed1e797f52f9f7dfb554bc9dc5d57 to your computer and use it in GitHub Desktop.
Google map api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function initialize() { | |
var zoom_area_coordinates = document.getElementById("coordinates").value.split(" ") | |
var zoom_level = 4; | |
if(request_type == "true" && (flash_value == "No Doctor found" || flash_value == "Please enter an address")){ | |
zoom_level = 4; | |
} | |
else if(request_type == "true"){ | |
zoom_level = 13; | |
} | |
old_zoom = zoom_level; | |
current_zoom = zoom_level; | |
var myLatlng = new google.maps.LatLng(parseFloat(zoom_area_coordinates[0]), parseFloat(zoom_area_coordinates[1])); | |
var myOptions = { | |
zoom: zoom_level, | |
center: myLatlng, | |
mapTypeId: google.maps.MapTypeId.ROADMAP | |
} | |
//for adding map on the page in DIV which has id as "map" | |
map = new google.maps.Map(document.getElementById("map"), myOptions); | |
TestMarker(); | |
} | |
// Function for adding a marker to the page. | |
function addMarker(location, clinic_name, dr_id, doctor_clinic_id) { | |
marker = new google.maps.Marker({ | |
position: location, | |
map: map, | |
doctor_id: dr_id, | |
doctor_clinic_id: doctor_clinic_id, | |
label: { | |
color: 'black' | |
}, | |
title: clinic_name | |
}); | |
// infowindow creation | |
var content = document.createElement("DIV"); | |
content.style.width = "absolute"; | |
content.style.height = "absolute"; | |
var infowindow = new google.maps.InfoWindow({ | |
content: content | |
}); | |
(function (marker) { | |
google.maps.event.addListener(marker, "click", function (e) { | |
$.ajax({ | |
url: '/get_doctor_info', | |
data: { | |
id: marker.doctor_id, | |
doctor_clinic_id: marker.doctor_clinic_id | |
} | |
}) | |
}); | |
google.maps.event.addListener(marker, "mouseover", function(evt) { | |
content.innerHTML = marker.getTitle(); | |
infowindow.open(map, marker); | |
$(".gm-style-iw").next("div").hide();// hiding CROSS sign from infowindow | |
$(".gm-style-iw").css("text-align","center"); | |
$(".gm-style-iw").css("width","absolute"); | |
}); | |
google.maps.event.addListener(marker, "mouseout", function(evt) { | |
infowindow.close(map, marker); | |
}); | |
})(marker); | |
} | |
function pinSymbol(color) { | |
return { | |
path: 'M 0,0 C -2,-20 -10,-22 -10,-30 A 10,10 0 1,1 10,-30 C 10,-22 2,-20 0,0 z', | |
fillColor: color, | |
fillOpacity: 1, | |
strokeColor: '#000', | |
strokeWeight: 2, | |
scale: 2 | |
}; | |
} | |
// Testing the addMarker function | |
function TestMarker() { | |
$.ajax({ | |
url: '/get_clinics', | |
data: { | |
is_search: request_type, | |
search_text: document.getElementById("p-code").value, | |
radius: parseInt(document.getElementById("radius").value), | |
search_doctor_type: document.getElementById("search_doctor_type").value | |
}, | |
success: function (res){ | |
var clinic; | |
if(res.length > 0){ | |
for (var i in res){ | |
clinic = res[i]; | |
var doctor_location = new google.maps.LatLng(clinic.latitude, clinic.longitude); | |
addMarker(doctor_location, clinic.clinic_name, clinic.doctor_id, clinic.clinic_id); | |
} | |
clinic = res[0] | |
var location = new google.maps.LatLng(clinic.latitude, clinic.longitude); | |
map.setCenter(location); | |
map.addListener('zoom_changed', function() { | |
old_zoom = current_zoom; | |
current_zoom = map.getZoom(); | |
zoomDiff = old_zoom - current_zoom; | |
if (zoomDiff > 0) | |
AddMoreMarker(); | |
}); | |
} | |
} | |
}) | |
} | |
function AddMoreMarker(){ | |
$.ajax({ | |
url: '/add_more_clinics', | |
data: { | |
is_search: request_type, | |
search_text: document.getElementById("p-code").value, | |
search_doctor_type: document.getElementById("search_doctor_type").value | |
}, | |
success: function (res){ | |
if(res.length > 0){ | |
for (var i in res){ | |
var clinic = res[i] | |
var doctor_location = new google.maps.LatLng(clinic.latitude, clinic.longitude); | |
addMarker(doctor_location, clinic.clinic_name, clinic.doctor_id, clinic.clinic_id); | |
} | |
} | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment