Advertisement
demetriusPop

working-showmap

Dec 14th, 2013
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.  
  5. Template Name: showmap
  6. */
  7.  
  8.  
  9. get_header();
  10.  
  11.  
  12.  
  13.  
  14. /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>> Read and Get From Table */
  15. if(isset($_POST['address']) && $_POST['address'] != '') {
  16. $user_search = esc_attr($_POST['address']);
  17.  
  18.  
  19. function get_address() {
  20. global $wpdb;
  21. global $user_search;
  22. $address_table = $wpdb->prefix . "address_table";
  23.  
  24. $query = $wpdb->get_results('SELECT * FROM ' . $address_table);
  25.  
  26.  
  27.  
  28. foreach($query as $single_query)
  29.  
  30. //Put the lat , lng results into array, return array and assign to var. Then use array keys where necessary
  31. $data = json_decode($single_query->json);
  32. $result = array();
  33. $result['lat'] = $data->results[0]->geometry->location->lat;
  34. $result['long'] = $data->results[0]->geometry->location->lng;
  35. $result['city'] = $single_query->city;
  36. return $result;
  37. }
  38. $latlong = get_address();
  39. ?><li><?php
  40. var_dump ($latlong);
  41. ?></li><?php
  42. }
  43.  
  44. ?>
  45.  
  46. <div id="map" style="width:300px; height:300px;"></div>
  47.  
  48. <!--Have to get lat and lng from database-->
  49. <script>
  50. var geocoder;
  51. var map;
  52. function initialize() {
  53. var mapOptions = {
  54. center: new google.maps.LatLng(<?php echo $latlong['lat'] ?>, <?php echo $latlong['long'] ?>),
  55. zoom: 8,
  56. mapTypeId: google.maps.MapTypeId.ROADMAP
  57. };
  58. var map = new google.maps.Map(document.getElementById("map"),
  59. mapOptions);
  60. }
  61. google.maps.event.addDomListener(window, 'load', initialize);
  62. </script>
  63.  
  64. <form method="post" action="" id="insertForm" name="insertForm">
  65. <input type="text" value="" placeholder="enter city" id="city" name="city">
  66. <input type="text" value="" placeholder="enter full address" id="address" name="address">
  67.  
  68. <input type="submit" value="search">
  69. </form>
  70.  
  71.  
  72.  
  73.  
  74. <?php
  75. get_footer();
  76.  
  77. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement