Advertisement
demetriusPop

Map

Dec 8th, 2013
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.  
  5. Template Name: addyardsale4
  6.  
  7. */
  8.  
  9. get_header();
  10.  
  11. /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>> Update address Table */
  12. function add_address() {
  13.  
  14. global $wpdb;
  15.  
  16.  
  17.  
  18. if ( isset( $_POST['address'] ) && $_POST['address'] != '') {
  19. $address = $_POST['address'];
  20. }
  21.  
  22. // JSON
  23. $address_results = gmap_geocode($address);
  24. $encoded_address_results = json_encode($address_results);
  25.  
  26. // Insert
  27. $address_table = $wpdb->prefix . "address_table";
  28.  
  29. $wpdb->insert($address_table, array('address' => $address, 'json' => $encoded_address_results) );
  30.  
  31.  
  32.  
  33. }
  34. add_address();
  35.  
  36.  
  37.  
  38.  
  39. /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>> Read and Get From Table */
  40. function get_address() {
  41. global $wpdb;
  42.  
  43. $address_table = $wpdb->prefix . "address_table";
  44.  
  45. $query = $wpdb->get_results('SELECT * FROM ' . $address_table);
  46.  
  47. global $single_query;
  48.  
  49. foreach($query as $single_query) {
  50.  
  51. global $single_query;
  52. // echo all rows
  53. // echo $single_query->json;
  54.  
  55. }
  56. $data = json_decode($single_query->json);
  57. $lat = $data->results[0]->geometry->location->lat;
  58. $long = $data->results[0]->geometry->location->lng;
  59. global $lat, $long;
  60. }
  61. get_address();
  62. global $lat, $long;
  63.  
  64.  
  65. ?>
  66.  
  67. <!--/* >>>>>>>>>>>>>>>>>>>>>>>>>>>>> Form and Map Script */-->
  68. <div id="map" style="width:300px; height:300px;"></div>
  69.  
  70. <!--Have to get lat and lng from database-->
  71. <script>
  72. var geocoder;
  73. var map;
  74. function initialize() {
  75. var mapOptions = {
  76. center: new google.maps.LatLng(<?php echo $lat ?>, <?php echo $long ?>),
  77. zoom: 8,
  78. mapTypeId: google.maps.MapTypeId.ROADMAP
  79. };
  80. var map = new google.maps.Map(document.getElementById("map"),
  81. mapOptions);
  82. }
  83. google.maps.event.addDomListener(window, 'load', initialize);
  84. </script>
  85.  
  86.  
  87. <form method="post" action="" id="insertForm" name="insertForm">
  88. <input type="text" value="" placeholder="enter text" id="address" name="address">
  89. <input type="submit" value="submit">
  90. </form>
  91.  
  92.  
  93. <?php
  94.  
  95. get_footer();
  96.  
  97. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement