Example #1
0
 public function generateAction($address, $info_bulle = '', $width = '100%', $height = '100%')
 {
     $geocoder = new \Geocoder\Geocoder();
     $adapter = new \Geocoder\HttpAdapter\CurlHttpAdapter();
     $chain = new \Geocoder\Provider\ChainProvider(array(new \Geocoder\Provider\FreeGeoIpProvider($adapter), new \Geocoder\Provider\HostIpProvider($adapter), new \Geocoder\Provider\GoogleMapsProvider($adapter, 'fr_FR', 'France', true), new \Geocoder\Provider\BingMapsProvider($adapter, 'AIzaSyBZ3sNuoMPrXGCNbhnEbGmfzGxOohhEX4E')));
     $geocoder->registerProvider($chain);
     $address = urldecode($address);
     $info_bulle = urldecode($info_bulle);
     // Récupération des coordonnées du programme
     try {
         $coordonnees = $geocoder->geocode($address);
     } catch (ChainNoResultException $e) {
         try {
             $coordonnees = $geocoder->geocode('France');
         } catch (ChainNoResultException $e) {
             return false;
         }
     }
     $info_content = '<div style="min-width:150px;text-align:center;">' . $info_bulle . '</div>';
     $info_window = new InfoWindow();
     $info_window->setAutoOpen(true);
     $info_window->setOpen(true);
     $info_window->setContent($info_content);
     $marker = new Marker();
     $marker->setPosition($coordonnees->getLatitude(), $coordonnees->getLongitude(), true);
     $marker->setAnimation('drop');
     $marker->setOption('clickable', true);
     $marker->setOption('flat', true);
     if ($info_bulle) {
         $marker->setInfoWindow($info_window);
     }
     // Création de la map
     $map = new Map();
     $map->setPrefixJavascriptVariable('map_');
     $map->setHtmlContainerId('map_canvas');
     $map->setAsync(true);
     $map->setAutoZoom(false);
     $map->setCenter($coordonnees->getLatitude(), $coordonnees->getLongitude(), true);
     $map->setMapOption('zoom', 12);
     $map->setMapOption('mapTypeId', MapTypeId::ROADMAP);
     $map->setMapOption('disableDefaultUI', false);
     $map->setMapOption('disableDoubleClickZoom', false);
     $map->setStylesheetOption('width', $width);
     $map->setStylesheetOption('height', $height);
     $map->setLanguage('fr');
     $map->addMarker($marker);
     return $map;
 }
Example #2
0
File: Geo.php Project: Quiss/Evrika
 public function fromIp($ip)
 {
     $geocoder = new \Geocoder\Geocoder();
     $adapter = new \Geocoder\HttpAdapter\CurlHttpAdapter();
     $chain = new \Geocoder\Provider\ChainProvider(array(new \Geocoder\Provider\FreeGeoIpProvider($adapter), new \Geocoder\Provider\HostIpProvider($adapter)));
     $geocoder->registerProvider($chain);
     return $geocoder->geocode($ip);
 }
Example #3
0
function get_location()
{
    $geocoder = new \Geocoder\Geocoder();
    $adapter = new \Geocoder\HttpAdapter\CurlHttpAdapter();
    $chain = new \Geocoder\Provider\ChainProvider(array(new \Geocoder\Provider\FreeGeoIpProvider($adapter), new \Geocoder\Provider\HostIpProvider($adapter), new \Geocoder\Provider\GoogleMapsProvider($adapter, 'en_US', 'USA', true), new \Geocoder\Provider\BingMapsProvider($adapter, '<API_KEY>')));
    $geocoder->registerProvider($chain);
    $result = $geocoder->geocode($_SERVER["REMOTE_ADDR"]);
    $dumper = new \Geocoder\Dumper\GeoJsonDumper();
    $geo_ar = $dumper->dump($result);
    return json_decode($geo_ar, true);
}
Example #4
0
$file = "zipcodes_num_fr.csv";
$new_file = "zipcode-belgium.csv";
$new_file_json = "zipcode-belgium.json";
$export = array();
if (($handle = fopen($file, "r")) !== FALSE) {
    $fp = fopen($new_file, 'w');
    $geocoder = new \Geocoder\Geocoder();
    $adapter = new \Geocoder\HttpAdapter\CurlHttpAdapter();
    $chain = new \Geocoder\Provider\ChainProvider(array(new \Geocoder\Provider\OpenStreetMapProvider($adapter, 'be')));
    $geocoder->registerProvider($chain);
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        if ($data[2] == "") {
            continue;
        }
        try {
            $addr = $data[0] . ' ' . $data[1] . ' Belgium';
            $geocode = $geocoder->geocode($addr);
            $row = array("zip" => $data[0], "city" => mb_convert_case($data[1], MB_CASE_TITLE, "UTF-8"), "lng" => $geocode->getLongitude(), "lat" => $geocode->getLatitude());
            $export[] = $row;
            fputcsv($fp, $row);
        } catch (\Exception $e) {
            echo $e->getMessage();
        }
        sleep(1);
    }
    fclose($fp);
    fclose($handle);
    $fp = fopen($new_file_json, 'w');
    fwrite($fp, json_encode($export));
    fclose($fp);
}
Example #5
0
 /**
  * Geo-locate an address
  *
  * @param   string  $address
  * @return  array
  */
 public static function locate($address)
 {
     $ip = false;
     if (filter_var($address, FILTER_VALIDATE_IP)) {
         $ip = true;
     }
     $adapter = new \Geocoder\HttpAdapter\CurlHttpAdapter();
     $p = array();
     // Get a list of providers
     if ($providers = \Event::trigger('geocode.onGeocodeProvider', array('geocode.locate', $adapter, $ip))) {
         foreach ($providers as $provider) {
             if ($provider) {
                 $p[] = $provider;
             }
         }
     }
     if (!count($p)) {
         return '';
     }
     // Instantiate the Geocoder service and pass it the list of providers
     $geocoder = new \Geocoder\Geocoder();
     $geocoder->registerProvider(new \Geocoder\Provider\ChainProvider($p));
     // Try to get some data...
     return $geocoder->geocode($address);
 }
Example #6
0
<?php

require 'vendor/autoload.php';
// Setup geocoder.
$adapter = new \Geocoder\HttpAdapter\CurlHttpAdapter();
$chain = new \Geocoder\Provider\ChainProvider(array(new \Geocoder\Provider\GoogleMapsProvider($adapter)));
$geocoder = new \Geocoder\Geocoder();
$geocoder->registerProvider($chain);
// Demo locations
$locations = array(array('address' => '3324 N California Ave, Chicago, IL, 60618', 'title' => 'Hot Dougs'), array('address' => '11 S White, Frankfort, IL, 60423', 'title' => 'Museum'), array('address' => '1000 Sterling Ave, , Flossmoor, IL, 60422', 'title' => 'Library'), array('address' => '2053 Ridge Rd, Homewood, IL, 60430', 'title' => 'Twisted Q'));
$mapdata = $marker_group = array();
foreach ($locations as $key => $value) {
    // Try to geocode.
    try {
        $geocode = $geocoder->geocode($value['address']);
        $longitude = $geocode->getLongitude();
        $latitude = $geocode->getLatitude();
        // Create map data array
        $mapdata[] = markerCreator($latitude, $longitude, $value['title'], $key);
        // Marker grouping array
        $marker_group[] = "marker{$key}";
    } catch (Exception $e) {
        echo $e->getMessage();
    }
}
function markerCreator($lat, $long, $label, $key)
{
    return "var marker{$key} = L.marker([{$lat}, {$long}]).addTo(map);\n    marker{$key}.bindPopup(\"{$label}\");";
}
?>
<!DOCTYPE html>