Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Map/coordinate questions

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

17 Replies
jagan
Luminary Alumni
Luminary Alumni

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.

robert_mika
Master III
Master III

You can search for those coordinates online.

Please see attached country long and lat

robert_mika
Master III
Master III

Hi Jagan,

Does this code work for any language?

Not applicable
Author

Hi Jagan, I'm going to try this now. I'll get back to you in a bit 😃

Not applicable
Author

Thank you Mika 😃

Not applicable
Author

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?

jagan
Luminary Alumni
Luminary Alumni

Hi Robert,

I tried it with different language and it is working.  Try this link

http://maps.googleapis.com/maps/api/geocode/xml?address=%E0%AE%9A%E0%AE%BF%E0%AE%99%E0%AF%8D%E0%AE%9...

Regards,

Jagan.

reddy-s
Master II
Master II

Hi Betty,

If you have the postcodes for the cities you can even use a KML file to plot your map.

jagan
Luminary Alumni
Luminary Alumni

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.