PHP SOAP Search request - how to include a SearchFilter RRS feed

  • Question

  • Hi,

    Hopefully there's a simple answer to this, but I'm stumped...

    I need to migrate a Web app from Google Maps to Bing Maps. It's mostly complete, but the final hurdle is to search for hospitals near a certain location.

    I'm using the PHP SOAP client, but I'm struggling to include a filter expression in the search request. This is the search request I'm trying, perhaps somebody could point out where I'm going wrong.

        [Credentials] => Array
                [ApplicationId] => key
        [Culture] => en-GB
        [Query] => hospital near address
        [SearchOptions] => Array
                [Count] => 5
                [Filters] => Array
                        [PropertyID] => 1
                        [FilterValue] => 11579
                        [CompareOperator] => Array
                                [CompareOperator] => Equals

    Ideally I'd like to simply return all the hospitals within a given radius of a latitude/longitude, but I'm certainly going to need to figure out the filter expression.

    Any advice is greatly appreciated.

    Tuesday, April 23, 2013 1:50 PM


All replies

  • Here is a blog post on how to do this:

    Wednesday, April 24, 2013 3:11 PM
  • Thanks for the pointer... I think it's got me a step closer (just different errors now).

    Perhaps I could slightly alter the question... given what I need to achieve: a list of the nearest hospitals to a given lat/long, is the SOAP Search service the best option?

    I've looked at the REST services, but they don't seem to offer the same level of features when it comes to searches (particularly filtering on entity type).

    Thanks again.


    Thursday, April 25, 2013 8:21 AM
  • Just following up from my comment on the blog post you recommended (there's probably more of an audience here). 

    I've adjusted the original code slightly, and I feel I'm getting really close. This is what I'm now trying:

    $searchClient = new SoapClient($searchServiceWsdl, array('classmap' => array('FilterExpression' => 'FilterExpression'),'trace' => 1));
    class FilterExpression {
    	public $PropertyID;
    	public $FilterValue;
    	public $CompareOperator;
    class CompareOperator {
    	public $CompareOperator;
    $compareOperator = new CompareOperator;
    $compareOperator->CompareOperator = 'Equals';
    $filterExpression = new FilterExpression;
    $filterExpression->PropertyID = 1;
    $filterExpression->FilterValue = '11579';
    $filterExpression->CompareOperator = $compareOperator;
    $options = array(
    	'Count' => 5,
    	'Filters' => $filterExpression
    $searchRequest = array(
    	'Credentials' => $credentials,
    	'Culture' => 'en-GB',
    	'Query' => $_POST['search']." near ".$_POST['address'],
    	'SearchOptions' => $options

    This gives:

    Catchable fatal error: Object of class CompareOperator could not be converted to string in...

    If I use and array for the CompareOperator, rather than a class, I get:

    The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter The InnerException message was 'Invalid enum value 'Array' cannot be deserialized into type 'Microsoft.VirtualEarth.PublicTypes.Common.CompareOperator'.

    Note: if I don't add the 'FilterExpression' to the SoapClient classmap, I just get :

    Fault occurred using Web Service: Cannot create an abstract class

    Wish there was a REST service for this!


    Thursday, April 25, 2013 2:49 PM
    • Proposed as answer by Ricky_Brundritt Thursday, April 25, 2013 5:45 PM
    • Marked as answer by MatBeard Thursday, April 25, 2013 7:00 PM
    Thursday, April 25, 2013 5:45 PM
  • Not sure how I missed that. I don't recall the Spatial Data Service being there last time I checked. Thanks for the heads-up.


    Thursday, April 25, 2013 7:01 PM