Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Template Name: addyardsale4
- */
- get_header();
- /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>> Update address Table */
- function add_address() {
- global $wpdb;
- if ( isset( $_POST['address'] ) && $_POST['address'] != '') {
- $address = $_POST['address'];
- }
- // JSON
- $address_results = gmap_geocode($address);
- $encoded_address_results = json_encode($address_results);
- // Insert
- $address_table = $wpdb->prefix . "address_table";
- $wpdb->insert($address_table, array('address' => $address, 'json' => $encoded_address_results) );
- }
- add_address();
- /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>> Read and Get From Table */
- function get_address() {
- global $wpdb;
- $address_table = $wpdb->prefix . "address_table";
- $query = $wpdb->get_results('SELECT * FROM ' . $address_table);
- global $single_query;
- foreach($query as $single_query) {
- global $single_query;
- // echo all rows
- // echo $single_query->json;
- }
- $data = json_decode($single_query->json);
- $lat = $data->results[0]->geometry->location->lat;
- $long = $data->results[0]->geometry->location->lng;
- global $lat, $long;
- }
- get_address();
- global $lat, $long;
- ?>
- <!--/* >>>>>>>>>>>>>>>>>>>>>>>>>>>>> Form and Map Script */-->
- <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 $lat ?>, <?php echo $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 text" id="address" name="address">
- <input type="submit" value="submit">
- </form>
- <?php
- get_footer();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement