dolibarr 18.0.6
google.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2010 Laurent Destailleur <eldy@users.sourceforge.net>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 * or see https://www.gnu.org/
17 */
18
28{
32 public $db;
33
37 public $error = '';
38
39 public $key;
40
47 public function __construct($db, $key)
48 {
49 $this->db = $db;
50 $this->key = $key;
51 }
52
53
62 public function getGeoCoordinatesOfAddress($address)
63 {
64 global $conf;
65
66 $i = 0;
67
68 // Desired address
69 $urladdress = "https://maps.google.com/maps/geo?q=".urlencode($address)."&output=xml&key=".urlencode($this->key);
70
71 // Retrieve the URL contents
72 require_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
73 $pagearray = getURLContent($urladdress, 'GET');
74 $page = $pagearray['content'];
75
76 $code = strstr($page, '<coordinates>');
77 $code = strstr($code, '>');
78 $val = strpos($code, "<");
79 $code = substr($code, 1, $val - 1);
80 //print $code;
81 //print "<br>";
82 $latitude = substr($code, 0, strpos($code, ","));
83 $longitude = substr($code, strpos($code, ",") + 1, dol_strlen(strpos($code, ",")) - 3);
84
85 // Output the coordinates
86 //echo "Longitude: $longitude ',' Latitude: $latitude";
87
88 $i++;
89 return "Longitude: $longitude, Latitude: $latitude";
90 }
91}
Class to manage Google API.
__construct($db, $key)
Constructor.
getGeoCoordinatesOfAddress($address)
Return geo coordinates of an address.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getURLContent($url, $postorget='GET', $param='', $followlocation=1, $addheaders=array(), $allowedschemes=array('http', 'https'), $localurl=0, $ssl_verifypeer=-1)
Function to get a content from an URL (use proxy if proxy defined).