Post

10 followers Follow
0
Avatar

location field extract data

Hi,
when using the internal "location" type, how can I extract e.g, city, country or the coordinates from it in calculations?

Regards,
Andreas

Andreas Forstinger

Please sign in to leave a comment.

17 comments

1
Avatar

Hi Andreas,

to get them in the same app (i.e.: extract in the same item):

var a = @map.join();
a.split(",")[0]   

This would return the street.
[0] = Street
[1] = Zip+City
[2] = State
[3]= Country

To get them in a related app if there is only one item with an address field related:

var a = @all of map.join();
a.split(",")[0]

If there are are multiple items related:

var a = @all of map;
result = [];
for(var i = 0; i < a.length;i++){
result.push(String[a[i]).split(",")[0]);
};
result.join("\n")  

This would return all streets as a list

Rainer

Rainer Grabowski 1 vote
Comment actions Permalink
0
Avatar

Thanks Rainer! Your solution works of course very well.

I was unclear in my question - especially I wanted to get the coordinates. Looking at https://developers.podio.com/doc/items#location it seemed the values are internally stored seperated and I wondered if I could access them like @location.[lat] or @location.["lng"] in a calculation.

Andreas Forstinger 0 votes
Comment actions Permalink
0
Avatar

As far as I know it's not possible to pull lat/lng with a calculation.

Rainer Grabowski 0 votes
Comment actions Permalink
0
Avatar

As I still have not found a solution for it: if I have an app with a location field e.g. "customers", how could I use the address data to filter my items based on country and city? This is something so basic that I wonder not every user having any kind of address data is requesting this?

With Rainer's solution I could have calculated fields showing the country but as this is text data and Podio obviously does not like text data it is up to no good except that I can export and then easily filter in Excel.
For now we still need to have additional category fields holding every possible country and our users must input data redundantly. Not cool at all!

Andreas Forstinger 0 votes
Comment actions Permalink
0
Avatar

Hello. 

I was able grab the CITY. Thanks Rainer. How do you get CITY, STATE? Thanks for any help. 

Dean Dang 0 votes
Comment actions Permalink
1
Avatar

When I tried this in the same app, I got:

[0] = Street address

[1] = City

[2] = State+ " "+Zip

[3] = Country

This is apparently because the addresses are broken by "," at those locations.

Could it be different for the USA addresses I was parsing?

-Mark

Mark Cannon 1 vote
Comment actions Permalink
3
Avatar

Dean,

I was able to get City, State using the following:

var a = @Map.join();
a.split(",")[1]+", "+a.split(",")[2].split(" ")[1]

Not sure what your result will be regarding my previous comment.

-Mark

Mark Cannon 3 votes
Comment actions Permalink
0
Avatar

Hi, i have a similar question. In the app 1 i want a calculation field to return the zipcode that is mentioned in app 2 in a location field. There is an outgoing relationship from app 1 to app 2. Anyone knows what code i have to use?

Nicolas Roegiers 0 votes
Comment actions Permalink
1
Avatar

Hi Nicholas,

normally the zip code is the last number in a location field (the street number is always before the zip code, cities and countries normally don't have a digit in their name). In my country Germany, in France or in the USA the zip code has always 5 digits (don't know how the zip code looks like in your country).

This given the zip code can be extracted very simple by deleting all other characters (and spaces etc.) and then extracting the last 5 digits:

@location field.join().replace(/[^0-9]/g,"").substr(-5) 

Another way I've described in this community post (see my first comment there).

Rainer

Rainer Grabowski 1 vote
Comment actions Permalink
0
Avatar

Hi Rainer,

As always your solution worked out. Thanks.

I have another problem regarding calculation fields giving null as a result when a field is empty.

In an app i have following fields :

1. reference field

2. date field

3. text field

I want to have a calculation field that shows the content of these 3 fields in the following way:

@all of title(reference field) + " - " + moment(@date field).format("DD/MM/YY") + @text field 

But when either the date field or text field is empty i don't want a "null" to show up in my calculation field. 

Do you know what code i have to use?

Greets,

Nicolas

Nicolas Roegiers 0 votes
Comment actions Permalink
0
Avatar

Hi Nicolas,

you can do it this way: 

(@all of title(reference field) + " - " + moment(@date field).format("DD/MM/YY") + @text field ).replace(/null/g,"")

That replaces all occurrences of  "null" (even if both, date and text, are empty), but leaves the dash (which is unnecessary when both other values are missing). For that you can enter: 

var ref = @all of title(reference field);
var date = moment(@date field).format("DD/MM/YY");
var text = @text field;
var title = text == null && date == null && ref != "" ? ref : (text != null || date != null) && ref != "" ? ref + " - " + date + text : ""
title.replace(/null/g,"")

Rainer

 

Rainer Grabowski 0 votes
Comment actions Permalink
0
Avatar

I tried this as well and I am not getting the same results. Here is my code

var a = @Address.join();
a.split(",")[0]
"http://www.zillow.com/webservice/GetDeepSearchResults.htm?zws-id=<ZWSID>&address=" + a.toString().split(',').join('+')[0] + "&citystatezip=" + a.split(' ').join('+')[2]

 

When I use this I get the following

http://www.zillow.com/webservice/GetDeepSearchResults.htm?zws-id=<ZWSID>&address=8&citystatezip=5

Christopher Gibbins 0 votes
Comment actions Permalink
2
Avatar

Hi Andreas. I would suggest you do a search for Scott Costello's JSON entry, either in YouTube or go to his site strugglinginvestor.com. Tons of free info, too. Our Podio community will be always indebted to him for all the time and effort he has put in. From day one, he has shared all the details of his progress, and NEVER asking for anything in return. We do owe him at least a big, huge THANK YOU.

Gus H. 2 votes
Comment actions Permalink
0
Avatar

Hi Gus,

thanks for pointing me there. Actually we went a similar route also using the Google Geocoder  - we just do not store it in a JSON field. We also do not use flows but PHP scripts called by hooks. It is great that there are lots of such workarounds, but it is also my feeling that we should not need to use them. Having JSON data in text fields is not very user friendly at all :)

 

 

Andreas Forstinger 0 votes
Comment actions Permalink
0
Avatar

Hello,

is possible use formula to get just city from adress map?

Actually I'm using this formula: @All of address.join("\n")

but I want to show just city 

my structure map is the following:

Adress

zip code

City

State

Nation 

Thank you :)

Teresa Cutrona 0 votes
Comment actions Permalink
0
Avatar

Any Help please advise any way to pull the State into its own field the Zip Code works great. 

Wendell Hankins 0 votes
Comment actions Permalink