dolibarr
21.0.0-alpha
Main Page
Related Pages
Topics
Classes
Files
File List
File Members
dolibarr_dev
htdocs
core
class
google.class.php
Go to the documentation of this file.
1
<?php
2
/* Copyright (C) 2010 Laurent Destailleur <eldy@users.sourceforge.net>
3
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 3 of the License, or
8
* (at your option) any later version.
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17
* or see https://www.gnu.org/
18
*/
19
28
class
GoogleAPI
29
{
33
public
$db;
34
38
public
$error =
''
;
39
43
public
$key;
44
51
public
function
__construct
($db, $key)
52
{
53
$this->db = $db;
54
$this->key = $key;
55
}
56
57
66
public
function
getGeoCoordinatesOfAddress
($address)
67
{
68
global $conf;
69
70
$i = 0;
71
72
// Desired address
73
$urladdress =
"https://maps.google.com/maps/geo?q="
.urlencode($address).
"&output=xml&key="
.urlencode($this->key);
74
75
// Retrieve the URL contents
76
require_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php'
;
77
$pagearray =
getURLContent
($urladdress,
'GET'
);
78
$page = $pagearray[
'content'
];
79
80
$code = strstr($page,
'<coordinates>'
);
81
$code = strstr($code,
'>'
);
82
$val = strpos($code,
"<"
);
83
$code = substr($code, 1, $val - 1);
84
//print $code;
85
//print "<br>";
86
$latitude = substr($code, 0, strpos($code,
","
));
87
$longitude = substr($code, strpos($code,
","
) + 1,
dol_strlen
((
string
) strpos($code,
","
)) - 3);
88
89
// Output the coordinates
90
//echo "Longitude: $longitude ',' Latitude: $latitude";
91
92
$i++;
93
return
"Longitude: $longitude, Latitude: $latitude"
;
94
}
95
}
GoogleAPI
Class to manage Google API.
Definition
google.class.php:29
GoogleAPI\__construct
__construct($db, $key)
Constructor.
Definition
google.class.php:51
GoogleAPI\getGeoCoordinatesOfAddress
getGeoCoordinatesOfAddress($address)
Return geo coordinates of an address.
Definition
google.class.php:66
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition
functions.lib.php:4790
getURLContent
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).
Definition
geturl.lib.php:42
Generated on Fri Nov 1 2024 01:00:26 for
dolibarr
by Doxygen 1.11.0