Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2012
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.77 KB | None | 0 0
  1. <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?libraries=places&sensor=false"></script>
  2. <style type="text/css">
  3. /*.post img{background-color: transparent;*/
  4.  
  5. *{ margin: 0; padding: 0; }
  6. html, body, #map_canvas
  7. {
  8. width: 100%;
  9. height: 350px;
  10. }
  11. img
  12. {
  13. border: 0;
  14. }
  15. .contentMap
  16. {
  17. width: 430px;
  18. border: 1px solid #336699;
  19. max-height:465px;
  20. overflow:auto;
  21. }
  22. .contentImg
  23. {
  24. float: left;
  25. width: 100px;
  26. margin-right: 10px;
  27. text-align: center;
  28. }
  29. .contentImg a
  30. {
  31. color: #369;
  32. font-size: 10px;
  33. }
  34. .contentTxt
  35. {
  36. float: left;
  37. width: 55%;
  38. }
  39. .clear{ clear: both; }
  40.  
  41. </style>
  42. <script type="text/javascript">
  43. var initialLoc;
  44. var the_map = null;
  45. var markersArray=[];
  46. var currency = "<?php echo get_option('cp_curr_symbol'); ?>";
  47. var no_thumb = "<?php echo plugins_url('/geo-ads/img/no-thumb.jpg'); ?>";
  48. var geocoder = new google.maps.Geocoder();
  49.  
  50. function gup( name )
  51. {
  52. name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  53. var regexS = "[\\?&]"+name+"=([^&#]*)";
  54. var regex = new RegExp( regexS );
  55. var results = regex.exec( window.location.href );
  56. if( results == null )
  57. return "";
  58. else
  59. return results[1];
  60. }
  61.  
  62. function loadMap(geoloc) {
  63. var latlng = new google.maps.LatLng(-25.344918, 131.033587);
  64. initialLoc = latlng;
  65. var myOptions = {
  66. zoom: 2,
  67. center: latlng,
  68. mapTypeId: google.maps.MapTypeId.TERRAIN
  69. };
  70.  
  71. the_map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
  72.  
  73. var map_cookie = getCookie("map_cookie");
  74. var loc = gup('loc');
  75.  
  76. if (loc == "" && geoloc != true && map_cookie != null && map_cookie != "") {
  77. map_cookie = map_cookie.split(",");
  78. var bounds = new google.maps.LatLngBounds();
  79. bounds.extend(new google.maps.LatLng(map_cookie[0], map_cookie[1]));
  80. bounds.extend(new google.maps.LatLng(map_cookie[2], map_cookie[3]));
  81. the_map.fitBounds(bounds);
  82. } else if (loc != "" && loc != "current") {
  83. loc = decodeURIComponent(loc);
  84. geocoder.geocode( { 'address': loc}, function(results, status) {
  85. if (status == google.maps.GeocoderStatus.OK) {
  86. the_map.setCenter(results[0].geometry.location);
  87. the_map.setZoom(13);
  88. }
  89. });
  90. } else {
  91. initGeolocation();
  92. }
  93.  
  94. google.maps.event.addListener(the_map, 'bounds_changed', function() {
  95. rememberLoc();
  96. currentPlaceName();
  97. refreshAds();
  98. });
  99. }
  100.  
  101. function refreshAds() {
  102.  
  103. jQuery('#block1').html('<img src="/wp-content/themes/classipress/images/ajax-loading.gif" style="margin-top: 30px; margin-left: 45%" />'); var bounds = the_map.getBounds();
  104. var southWest = bounds.getSouthWest();
  105. var northEast = bounds.getNorthEast();
  106.  
  107. var data = {
  108. action: 'query_geo_ads',
  109. range: 'true',
  110. exclude_categories : '',
  111. term_id : '0',
  112. term_slug : '',
  113. taxonomy_name : '',
  114. northeast_lng : northEast.lng(),
  115. northeast_lat : northEast.lat(),
  116. southwest_lng : southWest.lng(),
  117. southwest_lat : southWest.lat()
  118. };
  119.  
  120. var ajaxurl = '/wp-admin/admin-ajax.php';
  121.  
  122. // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
  123. jQuery.get(ajaxurl, data, function(response) {
  124. jQuery('#block1').html(response);
  125.  
  126. xOffset = 10;
  127. yOffset = 30;
  128.  
  129. jQuery('a.preview').hover(function(e){
  130. adTitle = jQuery(this).find('img').attr('alt');
  131. jQuery('body').append("<div id='preview'><img src='"+ this.rel +"' alt='' /><p>"+ adTitle +"</p></div>");
  132. jQuery('#preview')
  133. .css('top', (e.pageY - xOffset) + 'px')
  134. .css('left', (e.pageX + yOffset) + 'px')
  135. .fadeIn('fast');
  136. },
  137. function(){
  138. jQuery('#preview').remove();
  139. });
  140. jQuery('a.preview').mousemove(function(e){
  141. jQuery('#preview')
  142. .css('top', (e.pageY - xOffset) + 'px')
  143. .css('left', (e.pageX + yOffset) + 'px');
  144. });
  145. });
  146. }
  147.  
  148. function currentPlaceName() {
  149. var latlng = the_map.getCenter();
  150. geocoder.geocode({'latLng': latlng}, function(results, status) {
  151. if (status == google.maps.GeocoderStatus.OK) {
  152. if (results[1]) {
  153. jQuery('#l').val(results[1].formatted_address);
  154. } else if (results[0]) {
  155. jQuery('#l').val(results[0].formatted_address);
  156. }
  157. }
  158. });
  159. }
  160.  
  161. function initGeolocation()
  162. {
  163. if( navigator.geolocation )
  164. {
  165. // Call getCurrentPosition with success and failure callbacks
  166. navigator.geolocation.getCurrentPosition( success, fail );
  167. }
  168. else
  169. {
  170. alert("Sorry, your browser does not support geolocation services.");
  171. }
  172. }
  173.  
  174. function success(position)
  175. {
  176. var coords = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
  177. the_map.setCenter(coords);
  178. the_map.setZoom(13);
  179. }
  180.  
  181. function rememberLoc() {
  182. var bounds = the_map.getBounds();
  183. var ne = bounds.getNorthEast();
  184. var sw = bounds.getSouthWest();
  185. var lat1 = sw.lat();
  186. var long1 = sw.lng();
  187. var lat2 = ne.lat();
  188. var long2 = ne.lng();
  189. setCookie('map_cookie', lat1 + ',' + long1 + ',' + lat2 + ',' + long2, 100);
  190. }
  191.  
  192. function fail()
  193. {
  194. // Could not obtain location
  195. }
  196.  
  197. function setCookie(c_name,value,exdays)
  198. {
  199. var exdate=new Date();
  200. exdate.setDate(exdate.getDate() + exdays);
  201. var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
  202. document.cookie=c_name + "=" + c_value;
  203. }
  204.  
  205. function getCookie(c_name)
  206. {
  207. var i,x,y,ARRcookies=document.cookie.split(";");
  208. for (i=0;i<ARRcookies.length;i++)
  209. {
  210. x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  211. y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  212. x=x.replace(/^\s+|\s+$/g,"");
  213. if (x==c_name)
  214. {
  215. return unescape(y);
  216. }
  217. }
  218. }
  219.  
  220. // MAIN
  221. jQuery(document).ready(function(){
  222. loadMap();
  223.  
  224. // get ads
  225. var data = {
  226. action: 'query_geo_ads'
  227. };
  228.  
  229. jQuery.get(ajaxurl, data, function(r){
  230. var ads = jQuery.parseJSON(r);
  231. if (ads.length)
  232. process(ads);
  233. });
  234.  
  235. // end get ads
  236. function process(ads)
  237. {
  238. var bounds = new google.maps.LatLngBounds();
  239. jQuery.each(ads, function(k, v){
  240. var coord = new google.maps.LatLng(parseFloat(v.lat) + (Math.random()-.5)/150000, parseFloat(v.lng) + (Math.random()-.5)/150000);
  241. var mark = new google.maps.Marker({ position: coord, map: the_map});
  242. // on click Marker
  243. google.maps.event.addListener(mark, 'click', function(){
  244. var infoW = new google.maps.InfoWindow();
  245. var data = {
  246. action: 'get_image_url',
  247. id: v.post_id
  248. };
  249. jQuery.post(ajaxurl, data, function(img){
  250. var nice_title = (v.post_title.length >= 75) ? v.post_title.substring(0, 75)+'...' : v.post_title;
  251. if (v.price == null) v.price = '0';
  252. if (img)
  253. content = '<div id="contentInfoWindow class="contentMap">\
  254. <div class="contentImg">\
  255. <img src="'+img+'" />\
  256. </div>\
  257. <div class="contentTxt">\
  258. <a href="'+v.permalink+'"><h3>'+nice_title+'</h3></a>\
  259. <p>\
  260. Category: '+v.category+'\
  261. </p>\
  262. </div>\
  263. <div class="clear"></div>\
  264. </div>';
  265. else
  266. content = '<div id="contentInfoWindow class="contentMap">\
  267. <div class="contentImg">\
  268. <img src="'+no_thumb+'" />\
  269. </div>\
  270. <div class="contentTxt">\
  271. <a href="'+v.permalink+'"><h3>'+nice_title+'</h3></a>\
  272. <p>\
  273. Category: '+v.category+'\
  274. </p>\
  275. Price: '+currency+v.price+'\
  276. </div>\
  277. <div class="clear"></div>\
  278. </div>';
  279.  
  280. infoW.setContent(content);
  281. }); // ens ajax post
  282. infoW.open(the_map, this);
  283. }); // end onclick marker event handler
  284. markersArray.push(mark);
  285. bounds.extend(coord);
  286. });// end each
  287. var cluster = new MarkerClusterer(the_map, markersArray, {maxZoom: 15, minimumClusterSize: 4});
  288. //the_map.fitBounds(bounds);
  289. //cluster.fitMapToMarkers();
  290. }// end process
  291.  
  292. // Total count
  293. jQuery.post(ajaxurl, {action: 'query_total'}, function(r){
  294. jQuery('#total_count').fadeOut('fast').html("Total Geocoded Ads: "+r).fadeIn('fast');
  295. });
  296.  
  297. jQuery('a.geo-link').click(function() {
  298. initGeolocation();
  299. return false;
  300. });
  301. });// end document ready
  302.  
  303. </script>
  304. <div id="map_canvas"></div>
  305. <div id="total_count"></div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement