Skip to content

Instantly share code, notes, and snippets.

View geodatasource's full-sized avatar

geodatasource

View GitHub Profile
@geodatasource
geodatasource / distancecalculation.php
Created March 31, 2023 02:31
Distance calculation between two locations geolocated by using latitude and longitude in PHP
<?php
function distance($lat1, $lon1, $lat2, $lon2, $unit) {
if (($lat1 == $lat2) && ($lon1 == $lon2)) {
return 0;
}
else {
$theta = $lon1 - $lon2;
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
@geodatasource
geodatasource / neighboringcountries.php
Created March 31, 2023 02:10
Neighboring Countries enables user to lookup the associated land border countries (the neighboring countries) based on the input of country code in ISO3166-2 format. It will return the information of the neighboring countries code and name.
<?php
$apiKey = 'Enter_API_Key';
$params['format'] = 'json';
$params['country_code'] = 'US';
$query = '';
foreach($params as $key=>$value){
$query .= '&' . $key . '=' . rawurlencode($value);
}
@geodatasource
geodatasource / countryregion.php
Created March 31, 2023 01:40
Country-Region Dropdown Menu allows user to implement country-region dropdown list effortlessly where the region field will get updated automatically when there is a change on the country field.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Country-Region DropDown Menu</title>
<!-- link for jquery style -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
@geodatasource
geodatasource / locationsearch.php
Last active March 29, 2023 00:21
Location Search City API Sample Code - enable user to lookup for city name by using latitude and longitude coordinate.
// Please refer to https://geodatasource.com/web-service/location-search for the full sample codes and API key
<?php
$apiKey = 'Enter_API_Key';
$params['format'] = 'json';
$params['lat'] = 37.3861;
$params['lng'] = -122.084;
$query = '';