Appearance
Geocoder API
The Geocoder from Maps can also be used outside the area of the JS Maps. For example if you only need to geocode an address using Javascript, or in an other PHP app on your site.
API endpoint
The API is an ExpressionEngine action of Maps. The URL is
https://domain.com/index.php?ACT=[action_id]&method=api&type=[type][action_id]: the ID of theact_routeaction of theReinos_mapsclass (see theexp_actionstable). On a page with the{exp:reinos_maps:html_footer}tag, the full URL (without thetype) is also available in Javascript asREINOS_MAPS.api_path.[type]:address,latlngorip
Address
index.php?ACT=[action_id]&method=api&type=address
LatLng
index.php?ACT=[action_id]&method=api&type=latlng
IP
index.php?ACT=[action_id]&method=api&type=ip
Request
POST (or GET) the input field. Multiple values can be separated with a pipe |.
input=your-addressResponse
When nothing is found the response is {"success":false,"objects":[]}, when the input or type is missing it contains an error message.
{
"success":true,
"objects":[
{
"latitude":52.21115700000001,
"lat":52.21115700000001,
"longitude":5.9699231,
"lng":5.9699231,
"latlng":"52.211157,5.9699231",
"bounds":[
{
"south":52.172528,
"west":5.8925689,
"north":52.25032119999999,
"east":6.0582248
}
],
"street_name":null,
"street_number":null,
"city":"Amsterdam",
"locality":"Amsterdam",
"zipcode":null,
"admin_levels":[
{
"level":1,
"name":"Gelderland",
"code":"GE"
},
{
"level":2,
"name":"Amsterdam",
"code":"Amsterdam"
}
],
"city_district":null,
"sub_locality":null,
"country":"Netherlands",
"country_code":"NL",
"timezone":null,
"default_title":"Amsterdam, Netherlands",
"address":"Amsterdam, Netherlands"
}
]
}Example PHP
//set POST variables
$url = 'https://domain.com/index.php?ACT=[action_id]&method=api&type=address';
$fields = array(
'input' => urlencode('apeldoorn')
);
//url-ify the data for the POST
$fields_string = '';
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
//execute post
$result = curl_exec($ch);
print_r(json_decode($result));
//close connection
curl_close($ch);Example Javascript (jQuery)
jQuery.post(REINOS_MAPS.api_path + '&type=address', {input:'amsterdam'}, function(result){
console.log(result);
});