2010-01-17 18:54:57 +01:00
|
|
|
<?php
|
|
|
|
|
/* Copyright (C) 2010 Laurent Destailleur <eldy@users.sourceforge.net>
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2013-01-16 15:36:08 +01:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2010-01-17 18:54:57 +01:00
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* 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
|
2011-08-01 01:24:38 +02:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2010-01-17 18:54:57 +01:00
|
|
|
* or see http://www.gnu.org/
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2011-10-24 09:29:17 +02:00
|
|
|
* \file htdocs/core/class/google.class.php
|
2010-01-17 18:54:57 +01:00
|
|
|
* \brief A set of functions for using Google APIs
|
|
|
|
|
*/
|
2012-02-20 10:09:28 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class to manage Google API
|
|
|
|
|
*/
|
2010-01-17 18:54:57 +01:00
|
|
|
class GoogleAPI
|
|
|
|
|
{
|
|
|
|
|
var $db;
|
|
|
|
|
var $error;
|
|
|
|
|
|
|
|
|
|
var $key;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructor
|
|
|
|
|
*
|
2011-09-11 20:35:38 +02:00
|
|
|
* @param DoliDB $db Database handler
|
|
|
|
|
* @param string $key Google key
|
2010-01-17 18:54:57 +01:00
|
|
|
*/
|
2012-07-30 17:17:33 +02:00
|
|
|
function __construct($db,$key)
|
2010-01-17 18:54:57 +01:00
|
|
|
{
|
2012-02-20 10:09:28 +01:00
|
|
|
$this->db=$db;
|
2010-01-17 18:54:57 +01:00
|
|
|
$this->key=$key;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2012-02-20 10:09:28 +01:00
|
|
|
* Return geo coordinates of an address
|
|
|
|
|
*
|
|
|
|
|
* @param string $address Address
|
|
|
|
|
* Example: 68 Grande rue Charles de Gaulle,+94130,+Nogent sur Marne,+France
|
|
|
|
|
* Example: 188, rue de Fontenay,+94300,+Vincennes,+France
|
|
|
|
|
* @return string Coordinates
|
2010-01-17 18:54:57 +01:00
|
|
|
*/
|
|
|
|
|
function getGeoCoordinatesOfAddress($address)
|
|
|
|
|
{
|
|
|
|
|
global $conf;
|
|
|
|
|
|
|
|
|
|
$i=0;
|
|
|
|
|
|
|
|
|
|
// Desired address
|
2016-09-06 00:59:31 +02:00
|
|
|
$urladdress = "https://maps.google.com/maps/geo?q=".urlencode($address)."&output=xml&key=".$this->key;
|
2010-01-17 18:54:57 +01:00
|
|
|
|
|
|
|
|
// Retrieve the URL contents
|
|
|
|
|
$page = file_get_contents($urladdress);
|
|
|
|
|
|
|
|
|
|
$code = strstr($page, '<coordinates>');
|
|
|
|
|
$code = strstr($code, '>');
|
|
|
|
|
$val=strpos($code, "<");
|
|
|
|
|
$code = substr($code, 1, $val-1);
|
|
|
|
|
//print $code;
|
|
|
|
|
//print "<br>";
|
|
|
|
|
$latitude = substr($code, 0, strpos($code, ","));
|
2010-08-24 16:42:18 +02:00
|
|
|
$longitude = substr($code, strpos($code, ",")+1, dol_strlen(strpos($code, ","))-3);
|
2010-01-17 18:54:57 +01:00
|
|
|
|
|
|
|
|
// Output the coordinates
|
|
|
|
|
//echo "Longitude: $longitude ',' Latitude: $latitude";
|
|
|
|
|
|
|
|
|
|
$i++;
|
|
|
|
|
}
|
|
|
|
|
}
|