Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello everybody,
I'm trying to create a map in qlik sense. I know how to do it when you already have the coordinates (long and lat), but I don't have it in my data. I only have the names of cities and countries. I've tried it with googlemaps (someone I know tried to help me, but apparently it didn't work in qlik sense, which he found odd). Does anyone know a good way to get the coordinates for the different cities and countries that I have?
Any help would be useful. Have a good day 😃
Sincerely,
Betty Habtemariam
Hi,
Try this sample script
CustomerTable:
LOAD Quantity,
Customer,
City
FROM
C:\Users\378025\Desktop\Customer_info.xls
(biff, embedded labels, table is [Sheet1$]);
let noRows = NoOfRows('CustomerTable')-1;
for i=0 to $(noRows)
let b = peek('City',$(i),'CustomerTable');
GeocodeResponse:
LOAD
'$(b)' as CustomerCity,
([result/geometry/location/lat]) as latitude,
([result/geometry/location/lng]) as longitude
FROM [http://maps.googleapis.com/maps/api/geocode/xml?address=$(b)&sensor=false] (XmlSimple, Table is [GeocodeResponse]);
next i;
This will get fetch the latitude and longitudes using google maps apis.
Hope this helps you.
Regarsd,
Jagan.
You can search for those coordinates online.
Please see attached country long and lat
Hi Jagan,
Does this code work for any language?
Hi Jagan, I'm going to try this now. I'll get back to you in a bit 😃
Thank you Mika 😃
Okay, so I just hit the load button. I had to fix something first. Qlik Sense wants something calles a lib pathway, so I had to fix that.
Btw, I'm up in well over 15000 GeocodeResponse rows. Is that noemal?
Hi Robert,
I tried it with different language and it is working. Try this link
Regards,
Jagan.
Hi Betty,
If you have the postcodes for the cities you can even use a KML file to plot your map.
HI,
CustomerTable:
LOAD Quantity,
Customer,
City
FROM
C:\Users\378025\Desktop\Customer_info.xls
(biff, embedded labels, table is [Sheet1$]);
TempCity:
LOAD
DISTINCT City
RESIDENT CustomerTable;
let noRows = NoOfRows('TempCity')-1;
for i=0 to $(noRows)
let b = peek('City',$(i),'TempCity');
GeocodeResponse:
LOAD
'$(b)' as CustomerCity,
([result/geometry/location/lat]) as latitude,
([result/geometry/location/lng]) as longitude
FROM [http://maps.googleapis.com/maps/api/geocode/xml?address=$(b)&sensor=false] (XmlSimple, Table is [GeocodeResponse]);
next i;
DROP TABLE TempCity;
This will reduce the number of iterations.
The best suggestions get the Latitudes and Longitudes in an excel and use it in the Dashboard, instead of everytime getting from GoogleApis. In some Servers the internet access is restricted, at that time this won't work.
Regards,
Jagan.