Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Template Name: myTemp
- */
- get_header();
- /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>> INSERT//Update address Table */
- function add_address() {
- global $wpdb;
- if ( isset( $_POST['address'] ) && $_POST['address'] != '' && isset( $_POST['city']) && $_POST['city'] != '' ) {
- $address = $_POST['address'];
- $city = $_POST['city'];
- }
- // JSON
- $address_results = gmap_geocode($address);
- $encoded_address_results = json_encode($address_results);
- // Customize Query \\ send coordinates to coords column // send address to address column
- // Insert
- $address_table = $wpdb->prefix . "address_table";
- $wpdb->insert($address_table, array('address' => $address, 'json' => $encoded_address_results, 'city' => $city) );
- }
- 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;
- }
- //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;
- return $result;
- }
- $latlong = get_address();
- ?>
- <!--/* >>>>>>>>>>>>>>>>>>>>>>>>>>>>> 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 $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="submit">
- </form>
- <?php
- get_footer();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement