Jayant's Blog

Saturday, August 09, 2008

Using Php with ArcGIS Server 9.3 REST

The latest release of ArcGIS Server now supports REST access to the services. The best thing, it returns JSON. And at Php 5.2, there is support for JSON. So how simple is it to request an process a response?

Well, first use file_get_contents to call the REST endpoint. Next decode the JSON response as an object using json_decode. So here's a really simple sample to get a map image. Although I can't really see why you would use this rather than using the ArcGIS JavaScript API.

<?php
$url = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services" . "/Specialty/ESRI_StateCityHighway_USA/MapServer/export?f=json";
$response = file_get_contents($url);
$json = json_decode($response);

echo "<img src='" . $json->href . "' width='" . $json->width . "' height='" . $json->height . "' />";
?>

Labels: ,

1 Comments:

  • Hi,

    Is the javascript API fully supported in PHP? never used it and I have a client who wants to use JS api with PHP. My gut feel is that it is ok, as it is just JS in a web page.

    By Anonymous Anonymous, At Feb 13, 2009, 7:48:00 AM  

Post a Comment

Subscribe to Post Comments [Atom]



<< Home