PHP code example of benjaminhansen / arcgis-geocode

1. Go to this page and download the library: Download benjaminhansen/arcgis-geocode library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

benjaminhansen / arcgis-geocode example snippets




enjaminHansen\ArcGIS\Geocode\Api\Suggest;
use BenjaminHansen\ArcGIS\Geocode\Api\FindAddressCandidates;

// make a request for suggestions based on the text provided
$suggest_request = new Suggest();
$suggest_request->labelsAsPostalCity()->text('1600 Pennsylvania Ave. SE, Washington, DC 20003');

// get the first suggestion returned
$suggestion = $suggest_request->first();

// or get all suggestions returned
// $suggestions = $suggest_request->all();

// use a suggestion to look up coordinates, etc
$all_candidates = $suggestion->candidates()->all();
$first_candidate = $suggestion->candidates()->first();
$last_candidate = $suggestion->candidates()->last();

// or you can provide the text and magicKey values directly
// $candidates_request = new FindAddressCandidates($suggestion->text, $suggestion->magicKey);

// get the first candidate returned
// $candidate = $candidates_request->first();

// get the lat/lon values from the returned object
$latitude = $first_candidate->latitude();
$longitude = $first_candidate->longitude();