Advertisement
Guest User

Untitled

a guest
Jun 10th, 2016
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.62 KB | None | 0 0
  1. case "6": {$address = $_SESSION['mylocation']['address']; // GOOGLE MAP ?>
  2.  
  3. <div id="showmapbox">
  4.  
  5. <input name="custom[map_location]" id="form_map_location" class="controls" type="text" placeholder="<?php echo $address ?>" value="<?php echo $address /*echo get_post_meta($_GET['eid'],'map_location',true)*/?>" />
  6. <div id="wlt_map_location" style="height:300px;width:100%;"></div>
  7.  
  8. <div class="well well-sm">
  9. <b><?php echo $CORE->_e(array('add','46')); ?></b>
  10. <?php echo $CORE->_e(array('add','47')); ?>: <span id="wlt_dcountry" class="label label-primary"><?php if(isset($_GET['eid']) && get_post_meta($_GET['eid'],'map-country',true) != ""){ echo get_post_meta($_GET['eid'],'map-country',true); }else{ echo '<i class="glyphicon glyphicon-remove"></i>'; } ?></span>
  11. <?php echo $CORE->_e(array('add','48')); ?>: <span id="wlt_dstate" class="label label-primary"><?php if(isset($_GET['eid']) && get_post_meta($_GET['eid'],'map-state',true) != ""){ echo get_post_meta($_GET['eid'],'map-state',true); }else{ echo '<i class="glyphicon glyphicon-remove"></i>'; } ?></span>
  12. <?php echo $CORE->_e(array('add','49')); ?>: <span id="wlt_dcity" class="label label-primary"><?php if(isset($_GET['eid']) && get_post_meta($_GET['eid'],'map-city',true) != ""){ echo get_post_meta($_GET['eid'],'map-city',true); }else{ echo '<i class="glyphicon glyphicon-remove"></i>'; } ?></span>
  13. </div>
  14. </div>
  15.  
  16. <input type="hidden" id="map-long" name="custom[map-log]" <?php if(isset($_GET['eid'])){ echo 'value="'.get_post_meta($_GET['eid'],'map-log',true).'"'; } ?>>
  17. <input type="hidden" id="map-lat" name="custom[map-lat]" <?php if(isset($_GET['eid'])){ echo 'value="'.get_post_meta($_GET['eid'],'map-lat',true).'"'; } ?>>
  18. <input type="hidden" id="map-country" name="custom[map-country]" <?php if(isset($_GET['eid'])){ echo 'value="'.get_post_meta($_GET['eid'],'map-country',true).'"'; } ?>>
  19. <input type="hidden" id="map-address1" name="custom[map-address1]" <?php if(isset($_GET['eid'])){ echo 'value="'.get_post_meta($_GET['eid'],'map-address1',true).'"'; } ?>>
  20. <input type="hidden" id="map-address2" name="custom[map-address2]" <?php if(isset($_GET['eid'])){ echo 'value="'.get_post_meta($_GET['eid'],'map-address2',true).'"'; } ?>>
  21. <input type="hidden" id="map-address3" name="custom[map-address3]" <?php if(isset($_GET['eid'])){ echo 'value="'.get_post_meta($_GET['eid'],'map-address3',true).'"'; } ?>>
  22. <input type="hidden" id="map-zip" name="custom[map-zip]" <?php if(isset($_GET['eid'])){ echo 'value="'.get_post_meta($_GET['eid'],'map-zip',true).'"'; } ?>>
  23. <input type="hidden" id="map-state" name="custom[map-state]" <?php if(isset($_GET['eid'])){ echo 'value="'.get_post_meta($_GET['eid'],'map-state',true).'"'; } ?>>
  24. <input type="hidden" id="map-city" name="custom[map-city]" <?php if(isset($_GET['eid'])){ echo 'value="'.get_post_meta($_GET['eid'],'map-city',true).'"'; } ?>>
  25.  
  26.  
  27.  
  28. <script type="text/javascript">
  29.  
  30. var geocoder;var map;var marker = ''; var markers = [];
  31.  
  32. function initialize() {
  33.  
  34. if(typeof(map) != "undefined"){ return; }
  35.  
  36. // GET DEFAULT LOCATION
  37. <?php if(isset($_GET['eid']) && get_post_meta($_GET['eid'],'map-log',true) !=""){
  38. $DF_LOCATON = get_post_meta($_GET['eid'],'map-lat',true).",".get_post_meta($_GET['eid'],'map-log',true);
  39. }else{
  40. $DF_LOCATON = $GLOBALS['CORE_THEME']['google_coords'];
  41. }
  42.  
  43. if($DF_LOCATON == ""){ $DF_LOCATON ="0,0"; }
  44. $DF_ZOOM = $GLOBALS['CORE_THEME']['google_zoom'];
  45. if($DF_ZOOM == ""){ $DF_ZOOM = "5"; }
  46. ?>
  47.  
  48. // CREATE MAP CANVUS
  49. var myOptions = {mapTypeId: google.maps.MapTypeId.ROADMAP, zoomControl: true, scaleControl: true }
  50. map = new google.maps.Map(document.getElementById("wlt_map_location"), myOptions);
  51.  
  52. // LOAD MAP LOCATIONS
  53. var defaultBounds = new google.maps.LatLngBounds(
  54. new google.maps.LatLng(<?php echo $DF_LOCATON; ?>) );
  55. map.fitBounds(defaultBounds);
  56.  
  57. // ADD ON MARKER
  58. <?php if(isset($_GET['eid']) && get_post_meta($_GET['eid'],'map-log',true) !=""){ ?>
  59. var marker = new google.maps.Marker({
  60. position: new google.maps.LatLng(<?php echo get_post_meta($_GET['eid'],'map-lat',true); ?>,<?php echo get_post_meta($_GET['eid'],'map-log',true); ?>),
  61. map: map,
  62. animation: google.maps.Animation.DROP,
  63. icon: new google.maps.MarkerImage('<?php echo get_template_directory_uri(); ?>/framework/img/map/icon.png'),
  64. });
  65. <?php } ?>
  66.  
  67. // ADD SEARCH BOX
  68. map.controls[google.maps.ControlPosition.TOP_LEFT].push(document.getElementById('form_map_location'));
  69. var searchBox = new google.maps.places.SearchBox(document.getElementById('form_map_location'));
  70.  
  71. // EVENT
  72. google.maps.event.addListener(searchBox, 'places_changed', function() {
  73. var places = searchBox.getPlaces();
  74.  
  75. if (places.length == 0) {
  76. return;
  77. }
  78. for (var i = 0, marker; marker = markers[i]; i++) {
  79. marker.setMap(null);
  80. }
  81.  
  82. // For each place, get the icon, place name, and location.
  83. var bounds = new google.maps.LatLngBounds();
  84. for (var i = 0, place; place = places[i]; i++) {
  85. var image = {
  86. url: place.icon,
  87. size: new google.maps.Size(71, 71),
  88. origin: new google.maps.Point(0, 0),
  89. anchor: new google.maps.Point(17, 34),
  90. scaledSize: new google.maps.Size(25, 25)
  91. };
  92.  
  93.  
  94. addMarker(place.geometry.location);
  95. document.getElementById("map-long").value = place.geometry.location.lng();
  96. document.getElementById("map-lat").value = place.geometry.location.lat();
  97. getMyAddress(place.geometry.location,true)
  98.  
  99. bounds.extend(place.geometry.location);
  100. }
  101.  
  102. map.fitBounds(bounds);
  103. map.setZoom(12);
  104. });
  105.  
  106. // EVENT
  107. google.maps.event.addListener(map, 'bounds_changed', function() {
  108. var bounds = map.getBounds();
  109. searchBox.setBounds(bounds);
  110.  
  111. });
  112.  
  113. // EVENT
  114. google.maps.event.addListener(map, 'click', function(event){
  115. document.getElementById("map-long").value = event.latLng.lng();
  116. document.getElementById("map-lat").value = event.latLng.lat();
  117. getMyAddress(event.latLng,"yes");
  118. addMarker(event.latLng);
  119. });
  120.  
  121. // DEFAULT ZOOM LEVEL
  122. var listener = google.maps.event.addListener(map, "idle", function() {
  123. if (map.getZoom() != <?php echo $DF_ZOOM; ?>){ map.setZoom(<?php echo $DF_ZOOM; ?>); }
  124. google.maps.event.removeListener(listener);
  125. });
  126.  
  127. } // END INIT
  128.  
  129.  
  130. jQuery("#form_map_location").focusout(function() {
  131. setTimeout(function(){ getMapLocation(jQuery("#form_map_location").val()); }, 500);
  132.  
  133.  
  134. });
  135.  
  136. function getMapLocation(location){
  137. document.getElementById("map-state").value = "";
  138. var geocoder = new google.maps.Geocoder();
  139. if (geocoder) { geocoder.geocode({"address": location}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) {
  140.  
  141. map.setCenter(results[0].geometry.location);
  142. addMarker(results[0].geometry.location);
  143. getMyAddress(results[0].geometry.location,"no");
  144. document.getElementById("map-long").value = results[0].geometry.location.lng();
  145. document.getElementById("map-lat").value = results[0].geometry.location.lat();
  146. map.setZoom(<?php $default_zoom = $GLOBALS['CORE_THEME']['google_zoom']; if($default_zoom == ""){ $default_zoom = "9"; } echo $default_zoom; ?>);
  147. }});}
  148. }
  149.  
  150. function getMyAddress(location,setaddress){
  151.  
  152. jQuery('#showmapbox').show();
  153. google.maps.event.trigger(map, 'resize');
  154. var geocoder = new google.maps.Geocoder();
  155. var country = "";
  156. if (geocoder) {geocoder.geocode({"latLng": location}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) {
  157.  
  158. for (var i = 0; i < results[0].address_components.length; i++) {
  159.  
  160. var addr = results[0].address_components[i];
  161. //alert(addr.types[0]);
  162. switch (addr.types[0]){
  163.  
  164. case "street_number": {
  165. document.getElementById("map-address1").value = addr.long_name;
  166. } break;
  167.  
  168. case "route": {
  169. document.getElementById("map-address2").value = addr.long_name;
  170. } break;
  171.  
  172. case "locality":
  173. //case "postal_town":
  174. {
  175.  
  176. document.getElementById("map-address3").value = addr.long_name;
  177. document.getElementById("map-city").value = addr.long_name;
  178. } break;
  179.  
  180. case "postal_code": {
  181. document.getElementById("map-zip").value = addr.short_name;
  182. } break;
  183.  
  184. case "administrative_area_level_1": {
  185. document.getElementById("map-state").value = addr.long_name;
  186. } break;
  187.  
  188. case "administrative_area_level_2": {
  189. document.getElementById("map-state").value = addr.long_name;
  190. } break;
  191.  
  192. case "administrative_area_level_3": {
  193. document.getElementById("map-state").value = document.getElementById("map-state").value + addr.long_name;
  194. } break;
  195.  
  196. case "country": {
  197. document.getElementById("map-country").value = addr.short_name;
  198. } break;
  199.  
  200. } // end switch
  201.  
  202. } // end for
  203.  
  204. // NOW SET THE DISPLAY VALUES
  205. jQuery('#wlt_dcity').html(document.getElementById("map-city").value);
  206. jQuery('#wlt_dstate').html(document.getElementById("map-state").value);
  207. jQuery('#wlt_dcountry').html(document.getElementById("map-country").value);
  208.  
  209. if(setaddress == "yes"){
  210. document.getElementById("form_map_location").value = results[0].formatted_address;
  211. }
  212.  
  213. map.setCenter(results[0].geometry.location);
  214. map.setZoom(15);
  215.  
  216. } }); }}
  217.  
  218.  
  219. function addMarker(location) {
  220. if (marker=='') {
  221.  
  222.  
  223. marker = new google.maps.Marker({ position: location, map: map, draggable:true, animation: google.maps.Animation.DROP, });
  224.  
  225.  
  226. google.maps.event.addListener (marker, 'dragend', function (event){
  227. document.getElementById("map-long").value = event.latLng.lng();
  228. document.getElementById("map-lat").value = event.latLng.lat();
  229. getMyAddress(event.latLng,"yes");
  230. addMarker(event.latLng);
  231. });
  232.  
  233.  
  234. }
  235. marker.setPosition(location);
  236. map.setCenter(location);
  237. }
  238.  
  239. <?php if($DISPLAYSTYLE == "small"){ ?>
  240. // LOAD MAP BOX
  241. jQuery(document).ready(function() {
  242.  
  243. setTimeout(function(){ initialize(); }, 1000);
  244.  
  245. });
  246. <?php }else{ ?>
  247. // LOAD MAP BOX
  248. jQuery(document).ready(function() {
  249. jQuery( ".mapboxlink" ).click(function() {
  250. setTimeout(function(){ initialize(); }, 1000);
  251. });
  252. });
  253. <?php } ?>
  254. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement