// JavaScript Document var map; //Sedes //BUENOS AIRES - SEDE CENTRAL; var markerSede1; //BAHÍA BLANCA; var markerSede2; //CÓRDOBA; var markerSede3; //CORRIENTES; var markerSede4; //Consul //MAR DEL PLATA; var markerConsul1; //MENDOZA; var markerConsul2; //Neuquén; var markerConsul3; //ROSARIO; var markerConsul4; //SALTA; var markerConsul5; //SAN LUÍS; var markerConsul6; //SAN JUAN; var markerConsul7; //TANDIL; var markerConsul8; //TUCUMÁN; var markerConsul9; //TIERRA DEL FUEGO; var markerConsul10; var pointers = { //sedes Sede1: {type: 'sede', lat: -34.598022, lng: -58.411877, marker: ''}, Sede2: {type: 'sede', lat: -38.720466, lng: -62.272273, marker: ''}, Sede3: {type: 'sede', lat: -31.42841, lng: -64.18788, marker: ''}, Sede4: {type: 'sede', lat: -27.469506, lng: -58.839231, marker: ''}, //Consultorios Consul1: {type: 'Consul', lat: -38.0178625, lng: -57.565886, marker: ''}, Consul2: {type: 'Consul', lat: -32.866445, lng: -68.828869, marker: ''}, Consul3: {type: 'Consul', lat: -38.948408, lng: -68.063441, marker: ''}, Consul4: {type: 'Consul', lat: -32.940493, lng: -60.648311, marker: ''}, Consul5: {type: 'Consul', lat: -24.78212, lng: -65.41582, marker: ''}, Consul6: {type: 'Consul', lat: -33.68385, lng: -65.46515, marker: ''}, Consul7: {type: 'Consul', lat: -31.538434, lng: -68.527246, marker: ''}, Consul8: {type: 'Consul', lat: -37.3195, lng: -59.1516, marker: ''}, Consul9: {type: 'Consul', lat: -26.831639, lng: -65.208388, marker: ''}, Consul10: {type: 'Consul', lat: -54.80421, lng: -68.30387, marker: ''}, }; var nearest; var nearestSede; var nearestConsultorio; var myLatlng = ''; function iniciaMapa() { if($('#map_canvas')){ var myOptions = { zoom: 11, mapTypeId: google.maps.MapTypeId.ROADMAP }; map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); /************BUENOS AIRES - SEDE CENTRAL*************/ pointers.Sede1.marker = new google.maps.Marker({ position: new google.maps.LatLng(pointers.Sede1.lat, pointers.Sede1.lng), map: map, title:"BUENOS AIRES - SEDE CENTRAL", icon: "https://maps.gstatic.com/mapfiles/ms2/micons/blue-dot.png" }); var infowindowSede1 = new google.maps.InfoWindow({ content: "

Buenos Aires – Sede Central

Av Córdoba 3200, Ciudad Autónoma de Buenos Aires,
Argentina.

" }); google.maps.event.addListener(pointers.Sede1.marker, 'click', function() { infowindowSede1.open(map,pointers.Sede1.marker); }); /***********************************/ /************BAHÍA BLANCA*************/ pointers.Sede2.marker = new google.maps.Marker({ position: new google.maps.LatLng(pointers.Sede2.lat, pointers.Sede2.lng), map: map, title:"BAHÍA BLANCA", icon: "https://maps.gstatic.com/mapfiles/ms2/micons/blue-dot.png" }); var infowindowSede2 = new google.maps.InfoWindow({ content: "

Sede Bahía Blanca

Castelli 156, Bahía Blanca, Buenos Aires, Argentina.

" }); google.maps.event.addListener(pointers.Sede2.marker, 'click', function() { infowindowSede2.open(map,pointers.Sede2.marker); }); /***********************************/ /************CÓRDOBA*************/ pointers.Sede3.marker = new google.maps.Marker({ position: new google.maps.LatLng(pointers.Sede3.lat, pointers.Sede3.lng), map: map, title:"CÓRDOBA", icon: "https://maps.gstatic.com/mapfiles/ms2/micons/blue-dot.png" }); var infowindowSede3 = new google.maps.InfoWindow({ content: "

Sede Córdoba

Buenos Aires 1053 2° A, Córdoba, Argentina.

" }); google.maps.event.addListener(pointers.Sede3.marker, 'click', function() { infowindowSede3.open(map,pointers.Sede3.marker); }); /***********************************/ /************CORRIENTES*************/ pointers.Sede4.marker = new google.maps.Marker({ position: new google.maps.LatLng(pointers.Sede4.lat, pointers.Sede4.lng), map: map, title:"CORRIENTES", icon: "https://maps.gstatic.com/mapfiles/ms2/micons/blue-dot.png" }); var infowindowSede4 = new google.maps.InfoWindow({ content: "

Sede Corrientes

San Martín 1018, Corrientes, Argentina.

" }); google.maps.event.addListener(pointers.Sede4.marker, 'click', function() { infowindowSede4.open(map,pointers.Sede4.marker); }); /***********************************/ /************MAR DEL PLATA*************/ pointers.Consul1.marker = new google.maps.Marker({ position: new google.maps.LatLng(pointers.Consul1.lat, pointers.Consul1.lng), map: map, title:"MAR DEL PLATA", icon: "https://maps.gstatic.com/mapfiles/ms2/micons/blue-dot.png" }); var infowindowConsul1 = new google.maps.InfoWindow({ content: "

Mar del Plata

Hipolito Yrigoyen 4193, Buenos Aires, Argentina

" }); google.maps.event.addListener(pointers.Consul1.marker, 'click', function() { infowindowConsul1.open(map,pointers.Consul1.marker); }); /***********************************/ /************MENDOZA*************/ pointers.Consul2.marker = new google.maps.Marker({ position: new google.maps.LatLng(pointers.Consul2.lat, pointers.Consul2.lng), map: map, title:"MENDOZA", icon: "https://maps.gstatic.com/mapfiles/ms2/micons/blue-dot.png" }); var infowindowConsul2 = new google.maps.InfoWindow({ content: "

Mendoza

Cnel. Díaz 95, Mendoza, Argentina

" }); google.maps.event.addListener(pointers.Consul2.marker, 'click', function() { infowindowConsul2.open(map,pointers.Consul2.marker); }); /***********************************/ /************Neuquén*************/ pointers.Consul3.marker = new google.maps.Marker({ position: new google.maps.LatLng(pointers.Consul3.lat, pointers.Consul3.lng), map: map, title:"Neuquén", icon: "https://maps.gstatic.com/mapfiles/ms2/micons/blue-dot.png" }); var infowindowConsul3 = new google.maps.InfoWindow({ content: "

Neuquén

Carlos H. Rodriguez 1002, Neuquén, Argentina.

" }); google.maps.event.addListener(pointers.Consul3.marker, 'click', function() { infowindowConsul3.open(map,pointers.Consul3.marker); }); /***********************************/ /************ROSARIO*************/ pointers.Consul4.marker = new google.maps.Marker({ position: new google.maps.LatLng(pointers.Consul4.lat, pointers.Consul4.lng), map: map, title:"ROSARIO", icon: "https://maps.gstatic.com/mapfiles/ms2/micons/blue-dot.png" }); var infowindowConsul4 = new google.maps.InfoWindow({ content: "

Rosario

Dorrego 462, Rosario, Santa Fe, Argentina.

" }); google.maps.event.addListener(pointers.Consul4.marker, 'click', function() { infowindowConsul4.open(map,pointers.Consul4.marker); }); /***********************************/ /************SALTA*************/ pointers.Consul5.marker = new google.maps.Marker({ position: new google.maps.LatLng(pointers.Consul5.lat, pointers.Consul5.lng), map: map, title:"SALTA", icon: "https://maps.gstatic.com/mapfiles/ms2/micons/blue-dot.png" }); var infowindowConsul5 = new google.maps.InfoWindow({ content: "

Salta

Av. Sarmiento 566 1er piso, Salta, Argentina.

" }); google.maps.event.addListener(pointers.Consul5.marker, 'click', function() { infowindowConsul5.open(map,pointers.Consul5.marker); }); /***********************************/ /************SAN LUÍS*************/ pointers.Consul6.marker = new google.maps.Marker({ position: new google.maps.LatLng(pointers.Consul6.lat, pointers.Consul6.lng), map: map, title:"SAN LUÍS", icon: "https://maps.gstatic.com/mapfiles/ms2/micons/blue-dot.png" }); var infowindowConsul6 = new google.maps.InfoWindow({ content: "

San Luis

Lavalle 490, Villa Mercedes, San Luis, Argentina

" }); google.maps.event.addListener(pointers.Consul6.marker, 'click', function() { infowindowConsul6.open(map,pointers.Consul6.marker); }); /***********************************/ /************SAN JUAN*************/ pointers.Consul7.marker = new google.maps.Marker({ position: new google.maps.LatLng(pointers.Consul7.lat, pointers.Consul7.lng), map: map, title:"SAN JUAN", icon: "https://maps.gstatic.com/mapfiles/ms2/micons/blue-dot.png" }); var infowindowConsul7 = new google.maps.InfoWindow({ content: "

San Juan

Entre Ríos Sur 343, San Juan, Argentina.

" }); google.maps.event.addListener(pointers.Consul7.marker, 'click', function() { infowindowConsul7.open(map,pointers.Consul7.marker); }); /***********************************/ /************TANDIL*************/ pointers.Consul8.marker = new google.maps.Marker({ position: new google.maps.LatLng(pointers.Consul8.lat, pointers.Consul8.lng), map: map, title:"TANDIL", icon: "https://maps.gstatic.com/mapfiles/ms2/micons/blue-dot.png" }); var infowindowConsul8 = new google.maps.InfoWindow({ content: "

Tandil

14 de julio 327, Tandil, Buenos Aires, Argentina.

" }); google.maps.event.addListener(pointers.Consul8.marker, 'click', function() { infowindowConsul8.open(map,pointers.Consul8.marker); }); /***********************************/ /************TUCUMÁN*************/ pointers.Consul9.marker = new google.maps.Marker({ position: new google.maps.LatLng(pointers.Consul9.lat, pointers.Consul9.lng), map: map, title:"TUCUMÁN", icon: "https://maps.gstatic.com/mapfiles/ms2/micons/blue-dot.png" }); var infowindowConsul9 = new google.maps.InfoWindow({ content: "

Tucumán

Crisóstomo Álvarez 728, San Miguel de Tucumán,
Tucumán, Argentina

" }); google.maps.event.addListener(pointers.Consul9.marker, 'click', function() { infowindowConsul9.open(map,pointers.Consul9.marker); }); /***********************************/ /************TIERRA DEL FUEGO*************/ pointers.Consul10.marker = new google.maps.Marker({ position: new google.maps.LatLng(pointers.Consul10.lat, pointers.Consul10.lng), map: map, title:"TIERRA DEL FUEGO", icon: "https://maps.gstatic.com/mapfiles/ms2/micons/blue-dot.png" }); var infowindowConsul10 = new google.maps.InfoWindow({ content: "

Tierra del Fuego

Gobernador Paz 317 1º A, Ushuaia, Tierra del Fuego, Argentina.

" }); google.maps.event.addListener(pointers.Consul10.marker, 'click', function() { infowindowConsul10.open(map,pointers.Consul10.marker); }); /***********************************/ myLatlng = getLatLong(); //Agregamos el marker mas cercano getLocation(); } } function centrar(marcador) { map.setCenter(marcador.getPosition()); map.setZoom(11); google.maps.event.trigger(marcador, 'click'); } function getLatLong() { var res; $.ajax({ type: 'POST', url: 'https://www.crescenti.com.ar/wp-admin/admin-ajax.php', data: {action: 'getLocation'}, async: false, success: function(response){ var json = JSON.parse(response); res = json; } }); return res; } function getNearest(type = false) { var here = new google.maps.LatLng(myLatlng.latitude, myLatlng.longitude); //var here = new google.maps.LatLng(-33.766404, -66.087728); var min = {distance: null, name: null}; for(var point in pointers){ if(!min.distance){ if(type){ if(type == pointers[point].type){ min.distance = google.maps.geometry.spherical.computeDistanceBetween(here, new google.maps.LatLng(pointers[point].lat, pointers[point].lng)); min.point = pointers[point]; min.name = point; } }else{ min.distance = google.maps.geometry.spherical.computeDistanceBetween(here, new google.maps.LatLng(pointers[point].lat, pointers[point].lng)); min.point = pointers[point]; min.name = point; } }else{ if(google.maps.geometry.spherical.computeDistanceBetween(here, new google.maps.LatLng(pointers[point].lat, pointers[point].lng)) < min.distance){ if(type){ if(type == pointers[point].type){ min.distance = google.maps.geometry.spherical.computeDistanceBetween(here, new google.maps.LatLng(pointers[point].lat, pointers[point].lng)); min.point = pointers[point]; min.name = point; } }else{ min.distance = google.maps.geometry.spherical.computeDistanceBetween(here, new google.maps.LatLng(pointers[point].lat, pointers[point].lng)); min.point = pointers[point]; min.name = point; } } } } return min; } function getLocation() { nearest = getNearest(); nearestSede = getNearest('sede'); nearestConsultorio = getNearest('Consul'); // Sedes Page - Sedes if($('section.sedes').length || $('section.solicitar-turno').length){ centrar(nearestSede.point.marker); setTimeout(function(){ $('.sedes').removeClass('loading'); }, 700); setTimeout(function(){ $('.sede-mas-cercana#' + nearest.name).fadeIn(400); }, 1300); } if($('section.solicitar-turno').length || $('body.landing-page').length){ // Solicitar Turno Page - Sede más cercana setTimeout(function(){ $('.col-llamar .sedes.loading').removeClass('loading'); }, 700); setTimeout(function(){ $('.col-llamar .sedes .sede-mas-cercana#' + nearest.name).fadeIn(400); }, 1300); // Solicitar Turno Page - Sedes y Consultorios Autorizados centrar(nearestSede.point.marker); setTimeout(function(){ $('.sedes-content').removeClass('loading'); }, 700); setTimeout(function(){ $('.sedes-content .box-content#box' + nearestSede.name).fadeIn(400); }, 1300); setTimeout(function(){ $('.consultorios-content').removeClass('loading'); }, 700); setTimeout(function(){ $('.consultorios-content .box-content#box' + nearestConsultorio.name).fadeIn(400); }, 1300); } } jQuery(document).ready(function(){ if(typeof showMap !== 'undefined' && showMap) { iniciaMapa(); } })