// JavaScript Document var map; //Sedes //Consul var pointers = { //sedes //Consultorios }; 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); 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(); } })