Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Template Name: showmap
- */
- get_header();
- /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>> Read and Get From Table */
- if(isset($_POST['address']) && $_POST['address'] != '') {
- $user_search = esc_attr($_POST['address']);
- function get_address() {
- global $wpdb;
- global $user_search;
- $address_table = $wpdb->prefix . "address_table";
- $query = $wpdb->get_results('SELECT * FROM ' . $address_table);
- foreach($query as $single_query)
- //Put the lat , lng results into array, return array and assign to var. Then use array keys where necessary
- $data = json_decode($single_query->json);
- $result = array();
- $result['lat'] = $data->results[0]->geometry->location->lat;
- $result['long'] = $data->results[0]->geometry->location->lng;
- $result['city'] = $single_query->city;
- return $result;
- }
- $latlong = get_address();
- ?><li><?php
- var_dump ($latlong);
- ?></li><?php
- }
- ?>
- <div id="map" style="width:300px; height:300px;"></div>
- <!--Have to get lat and lng from database-->
- <script>
- var geocoder;
- var map;
- function initialize() {
- var mapOptions = {
- center: new google.maps.LatLng(<?php echo $latlong['lat'] ?>, <?php echo $latlong['long'] ?>),
- zoom: 8,
- mapTypeId: google.maps.MapTypeId.ROADMAP
- };
- var map = new google.maps.Map(document.getElementById("map"),
- mapOptions);
- }
- google.maps.event.addDomListener(window, 'load', initialize);
- </script>
- <form method="post" action="" id="insertForm" name="insertForm">
- <input type="text" value="" placeholder="enter city" id="city" name="city">
- <input type="text" value="" placeholder="enter full address" id="address" name="address">
- <input type="submit" value="search">
- </form>
- <?php
- get_footer();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement