Postcode issues

I have tried to use postcode uri but when I try and get the coordinates, it fouls up telling me it exceeds text length. any advice thank you :slight_smile:

Hi Struan.

Your images, unfortunately, are unreadable so I can't comment on " it fouls up telling me it exceeds text length." What is the exact error message..a screen capture probably shows information to indicate where you request is fouling up..

A probable issue is you are not using a Label to assign WebError the value of responseContent

You are getting back a json (here is an example for Buckingham Palace)

{"status":200,"result":{"postcode":"SW1A 1AA","quality":1,"eastings":529090,"northings":179645,"country":"England","nhs_ha":"London","longitude":-0.141588,"latitude":51.501009,"european_electoral_region":"London","primary_care_trust":"Westminster","region":"London","lsoa":"Westminster 018C","msoa":"Westminster 018","incode":"1AA","outcode":"SW1A","parliamentary_constituency":"Cities of London and Westminster","admin_district":"Westminster","parish":"Westminster, unparished area","admin_county":null,"admin_ward":"St James's","ced":null,"ccg":"NHS Central London (Westminster)","nuts":"Westminster","codes":{"admin_district":"E09000033","admin_county":"E99999999","admin_ward":"E05000644","parish":"E43000236","parliamentary_constituency":"E14000639","ccg":"E38000031","ccg_id":"09A","ced":"E99999999","nuts":"UKI32"}}}

You can use the dictionary blocks to access the various elements

will return the lon and lat values.

You may also want to move blocks into the Web1.gotText block - e.g calcDistance etc.

2 Likes

Thanks for your help in this instance, yes I was trying to get all the blocks visible (I think my coding is maybe a little chaotic) :slight_smile: This is what I hope to achieve,

I am trying to use the location sensor which provides your current location. Then in the next part, i wanted to get the data through postcodes api. However I knew that if I wanted the second location, then I would have to convert a postcode to the coordinates so that I can then calculate the distance between where you are and the location you have added in the postcode. Hope that makes sense. CHEERS, TIMAI2 I will try that.

My error, which I screengrabbed on my phone, says, The operation - cannot accept the argument: , ["not found"],[55.12705]

I think its the location changed, I was hoping to basically show your current location which it does. Then I think the latter part is breaking showing the destination which you are getting with responsecontent. Sorry, I hope this clarifies it better. Thanks again for any input in this.

I notice you are calling procedure calculateDistance immediately after issuing a Web Get.
Does that procedure depend on global variables that are set in the Web GotText event?
If so, you should move that procedure call to the bottom of the Web GotText event, where the global variables are freshly updated.
Otherwise, you are calculating based on values that have not yet arrived.

Yes. I have the two variables of the location sensor and then getting the two variables from the json code. It does say not found, would that be the reason. Thanks I will work on it tonight.

This is probably a dumb question but to use the dictionary block, do I have to establish creating a dictionary for the block to work? I have tried to retrieve the location and show through the text box but it says not found on both instances. I added a global dictionary but still not finding the latitude and longitude using json

Provide a DoIt image. I suspect the device provided coordinates do not match the coordinates you are comparing them to EXACTLY. Seldom will the coordinates provided by the LocationSensor match a hard coded pair entered manually. If the entered latitude for example is 30.0 and the device indicates 30.001, you will not obtain a match.

Why not provide an example here showing a typical LocationSensor value and tell us what value is in the TextBox. If the values are different, certainly they will not provide a match with your Dictionary.


This is where I have got to so far.

Did I not show you how to do this in an earlier post ?

yes TIMAI2 you did, thanks for that direction on using postcode.io, Ive tried using your code but just get "not found" when I try and put it in a text box. I wasn't sure if you had to create a dictionary but I tried that and still a problem. (This is probably my attempt at implimenting your working code with my code that is the issue).

UPDATE : I changed the postcode to text, than using the postcode.text box and that works. yet I was hoping to basically have it so that you can type in the postcode, rather than a set one. Hope that makes sense.

This fixed it but was hoping to get the user to input there postcode, to then convert to lat and long. This is great :slight_smile:

  1. Go back and look again, use the JsonTextDecodeWithDictionaries block, not the JSONTextDecode block
  2. Your user can enter a postcode in a textbox, you will just have to remove the spaces, if any, from what they typed, so postcode.io can accept the postcode. SW1A1AA not SW1A 1AA. You can use the text replacement block for that.
1 Like

BIG thank you,

TIMAI2Power User, SteveJG
ABGPower User

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.