Advertisement
Guest User

locationcontroller

a guest
Oct 6th, 2015
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. <?php
  2. class Locationcontroller extends CI_Controller{
  3. public function __construct() {
  4. parent::__construct();
  5.  
  6. $this->load->helper('url');
  7. }
  8. public function index(){
  9. $this->load->view('locationview');
  10. }
  11. public function getLocation(){
  12.  
  13. $address = $this->input->post('location');
  14. $coordinates = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($address) . '&sensor=true');
  15. $coordinates = json_decode($coordinates);
  16.  
  17. // echo 'Latitude:' . $coordinates->results[0]->geometry->location->lat;
  18. // echo 'Longitude:' . $coordinates->results[0]->geometry->location->lng;
  19.  
  20.  
  21. $lat = $coordinates->results[0]->geometry->location->lat;
  22. $lng = $coordinates->results[0]->geometry->location->lng;
  23. // $data=array('address'=> $this->input->post('address'));
  24. echo $lat.' '.$lng;
  25.  
  26.  
  27. }
  28. }
  29. /*
  30. * To change this license header, choose License Headers in Project Properties.
  31. * To change this template file, choose Tools | Templates
  32. * and open the template in the editor.
  33. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement