//////////////////////////////////////////////////////////////////////////////////////// // Events // //////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////// // Constants // //////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////// // Variables // //////////////////////////////////////////////////////////////////////////////////////// var frontendData = []; var cnterLat, cnterLng; var ajaxData = {}; //////////////////////////////////////////////////////////////////////////////////////// // Constructor & Destructor // //////////////////////////////////////////////////////////////////////////////////////// function gmwdReadyFunction(key){ // serach box if(gmwdmapData["enableSerchBox" + key] == 1){ initSerachBox(key); } // geolocate user if(gmwdmapData["geolocateUser" + key] == 1){ geoLocateUser(key); } //store locator if(gmwdmapData["enableStoreLocatior" + key] == 1 && gmwdmapData["widget" + key] == 0){ jQuery(".gmwd_my_location_store_locator" + key).click(function(){ var input = jQuery("#gmwd_store_locator_address" + key); getMyLocation(input); }); var input = /** @type {!HTMLInputElement} */( document.getElementById('gmwd_store_locator_address' + key)); var autocomplete = new google.maps.places.Autocomplete(input); autocomplete.bindTo('bounds', gmwdmapData["main_map" + key]); /*autocomplete.addListener('place_changed', function() { var place = autocomplete.getPlace(); if (!place.geometry) { window.alert("Autocomplete's returned place contains no geometry"); return; } cnterLat = place.geometry.location.lat(); cnterLng = place.geometry.location.lng(); });*/ jQuery("#gmwd_store_locator_search" + key).click(function(){ if(jQuery(".gmwd_store_locator_address" + key).val() == ""){ alert("Please set location."); return false; } if(gmwdmapDataOptions["storeLocatorCircle" + key]){ gmwdmapDataOptions["storeLocatorCircle" + key].setMap(null); } if(gmwdmapData["storeLocatorDistanceIn" + key] == "km"){ var radius = Number(jQuery("#gmwd_store_locator_radius" + key + " :selected").val())*1000; } else if(gmwdmapData["storeLocatorDistanceIn" + key] == "mile"){ var radius = Number(jQuery("#gmwd_store_locator_radius" + key + " :selected").val())*1609.34; } var geocoder = new google.maps.Geocoder(); geocoder.geocode({ "address": jQuery(".gmwd_store_locator_address" + key).val() }, function(results) { cnterLat = results[0].geometry.location.lat(); cnterLng = results[0].geometry.location.lng(); gmwdmapData["ajaxData" + key]["map_id"] = gmwdmapData["mapId" + key]; gmwdmapData["ajaxData" + key]["page"] = "map"; gmwdmapData["ajaxData" + key]["action"] = "get_ajax_store_loactor"; gmwdmapData["ajaxData" + key]["task"] = "get_ajax_store_loactor"; gmwdmapData["ajaxData" + key]["radius"] = Number(jQuery("#gmwd_store_locator_radius" + key + " :selected").val()); gmwdmapData["ajaxData" + key]["lat"] = cnterLat; gmwdmapData["ajaxData" + key]["lng"] = cnterLng; gmwdmapData["ajaxData" + key]["distance_in"] = gmwdmapData["storeLocatorDistanceIn" + key]; gmwdmapData["ajaxData" + key]["categories"] = []; jQuery.post(ajaxURL, gmwdmapData["ajaxData" + key], function (response){ gmwdmapData["mapMarkers" + key] = JSON.parse(response); for(var i=0; iGet Directions"; } infoWindow.setContent(contentString); } }); }, function() { alert('Error: Your browser doesn\'t support geolocation.'); }); } else { // Browser doesn't support Geolocation alert('Error: Your browser doesn\'t support geolocation.'); } } function getMyLocation(input){ if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(function(position) { var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); var geocoder = new google.maps.Geocoder(); geocoder.geocode({"latLng":latlng},function(data,status){ if(status == google.maps.GeocoderStatus.OK){ var address = data[1].formatted_address; input.val(address); cnterLat = data[1].geometry.location.lat(); cnterLng = data[1].geometry.location.lng(); } }); }); } else{ alert("Browser doesn't support Geolocation."); } } function initSerachBox(key){ var input = document.createElement("input"); input.id = "gmwd_serach_box" + key; input.type = "text"; input.style.cssText = "width:400px;"; input.setAttribute("onkeypress", "if(event.keyCode == 13) return false;") ; input.setAttribute("class", "gmwd_serach_box") ; searchBox = new google.maps.places.SearchBox(input); gmwdmapData["main_map" + key].controls[gmwdmapData["serchBoxPosition" + key]].push(input); gmwdmapData["main_map" + key].addListener('bounds_changed', function() { searchBox.setBounds( gmwdmapData["main_map" + key].getBounds()); }); searchBox.addListener('places_changed', function() { var places = searchBox.getPlaces(); var bounds = new google.maps.LatLngBounds(); places.forEach(function(place) { if (place.geometry.viewport) { // Only geocodes have viewport. bounds.union(place.geometry.viewport); } else { bounds.extend(place.geometry.location); } }); gmwdmapData["main_map" + key].fitBounds(bounds); }); } //////////////////////////////////////////////////////////////////////////////////////// // Getters & Setters // //////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////// // Private Methods // //////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////// // Listeners // ////////////////////////////////////////////////////////////////////////////////////////