Last active
May 6, 2016 00:43
-
-
Save TomiToivio/f9cdf5f94b51b85e4d07 to your computer and use it in GitHub Desktop.
geocoder.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Geocoder Plugin Example | |
Plugin URI: http://api.okf.fi/console/ | |
Description: Example WordPress Plugin for Geocoder API | |
Version: 1.0 | |
Author: Tomi Toivio | |
Author URI: http://fi.flossmanuals.net | |
License: GPL2 | |
*/ | |
/* Copyright 2013 Tomi Toivio (email: tomi@flossmanuals.net) | |
This program is free software; you can redistribute it and/or modify | |
it under the terms of the GNU General Public License, version 2, as | |
published by the Free Software Foundation. | |
This program is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with this program; if not, write to the Free Software | |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
*/ | |
class ttGeocoderWidget extends WP_Widget { | |
function SeAnalyticsWidget() { | |
// Instantiate the parent object | |
parent::__construct( false, 'Geocoder Widget' ); | |
} | |
function widget( $args, $instance ) { | |
echo '<div id="text-6" class="widget widget_text well nav nav-list"><h4 class="widgettitle nav-header">Geocoder Widget</h4><div class="textwidget">'; | |
tt_geocoder(); | |
echo '</div></div>'; | |
} | |
function update( $new_instance, $old_instance ) { | |
// Save widget options | |
} | |
function form( $instance ) { | |
// Output admin widget options form | |
} | |
} | |
function tt_register_geocoder_widget() { | |
register_widget( 'ttGeocoderWidgett' ); | |
} | |
add_action( 'widgets_init', 'tt_register_geocoder_widget' ); | |
function tt_geocoder() { | |
$osoite = "Kirstinmäki 11b28"; | |
$osoite = urlencode($osoite); | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, "http://api.okf.fi/gis/1/geocode.json?address=" . $osoite); | |
curl_setopt($ch, CURLOPT_HEADER, 0); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
$data = curl_exec($ch); | |
curl_close($ch); | |
$data = json_decode($data,true); | |
$data=$data['results']; | |
$data=$data[0]; | |
$data=$data['geometry']; | |
$data=$data['location']; | |
$longtitude = $data['lng']; | |
$latitude = $data['lat']; | |
echo $longtitude; | |
echo $latitude; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment