[Geomoose-users] [Pagc-devel] geocode_pagc.php for PAGC and Geomoose

whitedwarf at deadwrite.com whitedwarf at deadwrite.com
Thu Aug 5 01:04:09 EDT 2010


Hi Bill : Good work! I understand that some (perhaps all) versions of the
simplexml class in php do not handle namespaces properly in element
constructors. And thank you for sharing your code. Thanks, <= walter =>

> I've updated the geocode_pagc.php file with code that will handle an
> unresolved address.
>
> One thing I forgot to explain yesterday is that I'm handling the colon (:)
> in the returned xml from geocode_response.exe by saving the returned xml
> to a file, then stripping out the colon then bringing the file into
> simplexml_load_file.  Simplexml_load_file will not handle colons properly
> in this use.  If there's a better way to do this, please let me know.
>
> Here's the updated code...
>
> <?php
> $st_num = $_REQUEST['street_number'];
> $st_name = $_REQUEST['street_name'];
>
> $url =
> "http://gis_dataserver:8080/cgi-bin/geocode_response.exe?methodName=GeocodeRequest&Version=1.1&CountryCode=US&ResponseFormat=XML&RequestID=12345&maximumResponses=5&CompleteAddressNumber="
> . $st_num . "&CompleteStreetName=" . urlencode($st_name);
> $request_url = $url;
> $xmlget = file_get_contents($request_url);
> $replacepoint = str_replace('gml:Point','gmlPoint',$xmlget);
> $replacepos = str_replace('gml:pos','gmlpos',$replacepoint);
> file_put_contents('c:/temp/geocode_response.xml', $replacepos);
> $xml = simplexml_load_file('c:/temp/geocode_response.xml') or die("url not
> loading");
> $resolvedaddressnum =
> $xml->Response->GeocodeResponse->GeocodeResponseList->GeocodedAddress->Address->SiteAddress->CompleteAddressNumber;
> $resolvedstreetname =
> $xml->Response->GeocodeResponse->GeocodeResponseList->GeocodedAddress->Address->SiteAddress->CompleteStreetName->StreetName;
> $resolvedstreettype =
> $xml->Response->GeocodeResponse->GeocodeResponseList->GeocodedAddress->Address->SiteAddress->CompleteStreetName->PostType;
> $resolvedaddress = $resolvedaddressnum . " " . $resolvedstreetname . " " .
> $resolvedstreettype;
>
> $status =
> $xml->Response->GeocodeResponse->GeocodeResponseList[numberOfGeocodedAddresses];
> if ($status >= 1) {
>       // Successful geocode
>       $resolvedaddressnum =
> $xml->Response->GeocodeResponse->GeocodeResponseList->GeocodedAddress->Address->SiteAddress->CompleteAddressNumber;
>       $resolvedstreetname =
> $xml->Response->GeocodeResponse->GeocodeResponseList->GeocodedAddress->Address->SiteAddress->CompleteStreetName->StreetName;
>       $resolvedstreettype =
> $xml->Response->GeocodeResponse->GeocodeResponseList->GeocodedAddress->Address->SiteAddress->CompleteStreetName->PostType;
>       $resolvedaddress = $resolvedaddressnum . " " . $resolvedstreetname .
> " " . $resolvedstreettype;
>
> //print_r($xml);
>
> $coordinates =
> $xml->Response->GeocodeResponse->GeocodeResponseList->GeocodedAddress->gmlPoint->gmlpos;
>      $coordinatesSplit = split(" ", $coordinates);
>
>       // Format: Longitude, Latitude, Altitude
>       $lat = $coordinatesSplit[1];
>       $lng = $coordinatesSplit[0];
>
>  header('Content-type: application/xml');
>       print "<results>";
>       print "<script>";
>       print "<![CDATA[";
>       print "";
>       print "var p = new
> OpenLayers.Geometry.Point($lng,$lat);OpenLayers.Projection.transform(p,new
> OpenLayers.Projection('WGS84'),Map.getProjectionObject());GeoMOOSE.zoomToPoint(p.x,p.y,100);GeoMOOSE.addPopup(p.x,p.y,150,50,'<b>Address
> Resolved To:</b> <br/> $resolvedaddress');";
>       print "]]>";
>       print "</script>";
>       print "<html>";
>       print "<![CDATA[";
>       print "";
>       print "<b>Address Resolved To:</b> <br/> $resolvedaddress";
>       print "]]>";
>       print"</html>";
>       print "</results>";
> } else{
>   header('Content-type: application/xml');
>   print "<results>";
>   print "<script>";
>   print "</script>";
>   print "<html>";
>   print "<![CDATA[";
>   print "";
>   print "<h3><p style='color:red'>Unable to resolve address.</p></h3>";
>   print "]]>";
>   print"</html>";
>   print "</results>";
> }
>
> ?>
>
> Baldwin County Public Schools
> Bill Harbour
> GIS Coordinator
> Information Technology Services
> Baldwin County Board of Education
> 1071  B Ave
> Loxley, AL 36551
> V 251-580-1916
> F 251-972-6851
> Office 251-972-6850
> bharbour at bcbe.org<mailto:bharbour at bcbe.org>
> http://www.bcbe.org
> "When life gets too unreal, sit down with a good book." - Garrison Keillor
>
> ------------------------------------------------------------------------------
> The Palm PDK Hot Apps Program offers developers who use the
> Plug-In Development Kit to bring their C/C++ apps to Palm for a share
> of $1 Million in cash or HP Products. Visit us here for more details:
> http://p.sf.net/sfu/dev2dev-palm_______________________________________________
> Pagc-devel mailing list
> Pagc-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/pagc-devel
>








More information about the Geomoose-users mailing list