javaandroidtomtom-android-sdk

How to find the co-ordinates of a postal code using the tomtom API


Here's what I'm trying to do:

I see that there's a FuzzySearchQueryBuilder class provided, which I'm using in the following way:

FuzzySearchQuery query = FuzzySearchQueryBuilder.create("query")
            .withLanguage(Locale.getDefault().toLanguageTag())
            .withCountry("UK")
            .withExtendedPostalCodes("SN41AB, WF112AB")
            .build();

However the search returns an error, complaining about not being able to successfully parse the postcode value.

Looking at the various examples, I don't see one that is using a postcode search.

I've also looked at the Javadocs here, which talks about using these index values "PAD, POI, Str, XStr". But where does the post code fit in?

Is what I'm trying to do even possible? It seems like it should be, as the API specifically deals with postal codes. So I'm assuming it's just a question of using the correct parameter format. Could anyone provide an example of using the API in this way?


Solution

  • The documentation for withExtendedPostalCodes suggests this method is intended to be used quite differently from your sample:

    Indexes for which extended postal codes should be included in the results. Available indexes are: Addr, Geo, PAD, POI, Str, XStr. Value should be a comma separated list of index types (in any order) or "None" for no indexes, i.e. "PAD,Addr,POI"

    The string you pass in create is where address information should be provided. In addition, the correct country code to use here is "GB" rather than "UK". So your code should look something like:

    FuzzySearchQuery query = FuzzySearchQueryBuilder.create("SN41AB,WF112AB")
            .withLanguage(Locale.getDefault().toLanguageTag())
            .withCountry("GB")
            .build();
    
    // Do stuff with the results of query.