Example #1
0
function handle_form($address)
{
    $loc = getLatLong($address);
    echo "<pre>";
    print_r($loc);
    echo "</pre>";
}
Example #2
0
function pre_submission_handler($entry)
{
    // pass the entries relating to the address parts from form
    $query_string = $entry['2.1'] . "+" . $entry['2.3'] . "+" . $entry['2.4'] . "+" . $entry['2.5'] . "+" . $entry['2.5'];
    $coords = getLatLong($query_string);
    update_post_meta($entry['post_id'], 'lat', $coords['latitude']);
    update_post_meta($entry['post_id'], 'lng', $coords['longitude']);
}
    if (empty($_POST["country"])) {
        $country = "Netherlands";
    } else {
        $county = $request->country;
    }
    @($showName = $request->name);
    @($img = $request->img);
    @($showDate = $request->showDate);
    @($startTime = $request->showTime);
    @($link = $request->link);
    @($endTime = $request->showEnd);
    @($street = $request->street);
    @($city = $request->city);
    $address = str_replace(" ", "+", $street) . "+" . $city;
    $geoLat = getLatLong("Lat", $address, $country);
    $geoLong = getLatLong("Long", $address, $country);
    if ($geoLat != "" && $geoLong != "") {
        $mysqli->query("INSERT INTO `shows`(`name`, `img`, `link`, `showDate`, `startTime`, `endTime`, `geoLat`, `geoLong`) VALUES ('{$showName}','{$img}','{$link}','{$showDate}','{$startTime}','{$endTime}','{$geoLat}','{$geoLong}')");
    } else {
        echo "can't collect good geo data";
    }
} else {
    var_dump($request);
}
function getLatLong($type, $address, $country)
{
    $url = "http://maps.google.com/maps/api/geocode/json?address={$address}&sensor=false&region={$country}";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
Example #4
0
<?php

function getLatLong($code)
{
    $mapsApiKey = 'your-google-maps-api-key';
    $query = "http://maps.google.co.uk/maps/geo?q=" . urlencode($code) . "&output=json&key=" . $mapsApiKey;
    $data = file_get_contents($query);
    // if data returned
    if ($data) {
        // convert into readable format
        $data = json_decode($data);
        $long = $data->Placemark[0]->Point->coordinates[0];
        $lat = $data->Placemark[0]->Point->coordinates[1];
        return array('Latitude' => $lat, 'Longitude' => $long);
    } else {
        return false;
    }
}
print_r(getLatLong('SW1W 9TQ'));
Example #5
0
// get csv file from tmp upload dir
$csv = $_FILES['csv']['tmp_name'];
// parse csv into array
$csvAsArray = array_map('str_getcsv', file($csv));
// return the json array
// COUNT THE ARRAY
// $counted = array_count_values($csvAsArray);
// set the gps array for post geocoding
$gps = [];
// loop over addresses and get the geocode lat long
foreach ($csvAsArray as $key => $value) {
    // implode the address into one string
    $address = implode(" ", $value);
    // send to google maps geocode api
    // flawed as right now the HEX color code is on the end of the imploded string
    $coords = getLatLong($address);
    // add the return values to the $gps array for return to the initial page
    array_push($gps, $coords);
}
// return the values to the index.php page
echo json_encode($gps);
//echo json_encode($csvAsArray);
// TODO
// GEOCODE ADDRESSES IN THE LOOP LIKELY IN THIS PAGE
// RETURN DATA FORMATTED DIRECTLY FOR MAP MARKERS FROM THIS PAGE
// function to geocode address, it will return false if unable to geocode address
// function to get the lat long from the addresses
function getLatLong($address)
{
    // url encode the address
    $address = urlencode($address);
Example #6
0
            return false;
        }
        preg_match('!center:\\s*{lat:\\s*(-?\\d+\\.\\d+),lng:\\s*(-?\\d+\\.\\d+)}!U', $_result, $_match);
        $_coords['lat'] = $_match[1];
        $_coords['long'] = $_match[2];
    }
    return $_coords;
}
?>



<div id="mapper">
		
	  <?php 
$coordinates = getLatLong($address);
$lat = $coordinates['lat'];
$long = $coordinates['long'];
$latitude = str_replace('.', ',', $lat);
$longitude = str_replace('.', ',', $long);
?>
		
		
		
		 <div class="map" data-latitude="<?php 
echo $latitude;
?>
" data-longtitude="<?php 
echo $longitude;
?>
"></div>