1 .You need to install composer, Read how to install composer
2. Install git, Read how to install git
3. Clone repository with git
git clone https://github.com/AlifAbhiesa/Codeigniter-K-Means-Clistering.git
And Run Composer Update
composer update
4. Create your own Google API
You need 3 google API, google maps API to show routes, geocoding for translating address into Geographic Coordinates, and Distance matrix to provides distance between two place. Read how to get the API
4.1. Read how to setup Google Maps API
4.1. Read how to setup Geocoding API
4.1. Read how to setup Distance Matrix API
5. Configure Google API in your code
5.1. Placing Maps API
Open file /application/views/default/index.php and place your API key here
<script src="https://maps.googleapis.com/maps/api/js?key= YOUR API KEY" type="text/javascript"></script>
5.2. Placing Geocoding API
Open file /application/controller/Data.php and place your API key here
public function getGeo($location){
$httpClient = new \Http\Adapter\Guzzle6\Client();
$provider = new \Geocoder\Provider\GoogleMaps\GoogleMaps($httpClient, null, ' YOUR API KEY ');
$geocoder = new \Geocoder\StatefulGeocoder($provider, 'en');
$result = $geocoder->geocodeQuery(GeocodeQuery::create($location));
$Longitude = $result->first()->getCoordinates()->getLongitude();
$Latitude = $result->first()->getCoordinates()->getLatitude();
$coordinates = array(
'Longitude' => $Longitude,
'Latitude' => $Latitude
);
return $coordinates;
}
5.2. Placing Distance Matrix API
Open file /application/controller/Data.php and place your API key here
public function distance($LatOri,$LongOri,$LatDes,$LongDes){
$distance_data = file_get_contents('https://maps.googleapis.com/maps/api/distancematrix/json?&origins='.
$LatOri.','.$LongOri.'&destinations='.$LatDes.','.$LongDes.'&key= YOUR API KEY');
$distance_arr = json_decode($distance_data);
$result = $distance_arr->rows;
//result is a distance on Meter
return $result[0]->elements[0]->distance->value;
}
In this application i'm using 2 methode. K Means clustering to create the cluster of data, and Silhouette Coefficient to test the result cluster of K Means clustering. If you want to understand the flow of that method, you need to read this paper
1. Paper of K Means Clustering
2. Paper of Silhouette Coefficient
Read Me on Medium, Story about this application by Alif Abhiesa