Advertisement
demetriusPop

display map

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