Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
ngosz4074
Contributor III
Contributor III

Issue with Google Maps

Hello,

I'm trying to create an application using Google Maps and I have a table that has customer data with Zip Code and a table joining by Zip Code has latitude and longitude at the street and block level that I picked up from the Census Bureau.  I formatted the file into a .csv file and when I load into the script, the map appears as data points in Antarctica, when it should be in the U.S. 

I formatted the latitude and longitude as text so they would not sum up, but I'm not getting the correct data points.  My map script is as such:

-- I commented out the Google Map Key since I don't think we need one anymore:

// Google Maps Key

// get a key here http://code.google.com/apis/maps/signup.html

//key for my email: AIzaSyAIB-WFDEAtfLNwDAhvgd0JPxaPOYvDgj4

// number of seconds to wait for a URL datasource

set OpenUrlTimeout=10;

//gmap_key = 'AIzaSyCd3LDYwNeOvyk-V_JtbMvI9OH4vVQ7nGc';

max_zoom_level = 12; //maximum value 17

// Variables required for calculating map

// No need to change these

var_pi180= '=pi()/180';

var_lat_offset= '0';

var_mc2= '=256*pow(2,$(var_zoom))';

var_mc1= '=256*pow(2,($(var_zoom)-1))';

var_mid_lat= '=min(latitude)+(1+var_lat_offset)*((max(latitude)-min(latitude))/2)';

var_mid_long= '=min(longitude)+(max(longitude)-min(longitude))/2';

var_zoom= '=max(aggr(if(max( round(256*pow(2,(_zoom_level -1)))+( longitude  *((256*pow(2,_zoom_level ))/360)) )-min( round(256*pow(2,(_zoom_level -1)))+

( longitude  *((256*pow(2,_zoom_level ))/360)) ) <map_size_x AND max((256*pow(2,(_zoom_level-1)))+((0.5*log((1+(sin((latitude)*pi()/180)))/(1-(sin((latitude)*pi()/180)))))*((-256*pow(2,_zoom_level))/(2*pi()))))-min((256*pow(2,(_zoom_level-1)))

+((0.5*log((1+(sin((latitude)*pi()/180)))/(1-(sin((latitude)*pi()/180)))))*((-256*pow(2,_zoom_level))/(2*pi()))))<map_size_y,_zoom_level,1),_zoom_level))';

var_maptype= '=if(isnull(only(maptype)),fieldvalue( '&chr(39)&'maptype'&chr(39)&', 1 ),maptype)';

map_size_x=    '400';

map_size_y=     '400';

//var_maptype = '=if(isnull(only(maptype)),fieldvalue( '&chr(39)&'maptype'&chr(39)&', 1 ),maptype)';

vMinXaxis       = ' (256*pow(2,((var_zoom)-1)))+((var_mid_long)*((256*pow(2,(var_zoom)))/360))-(def_map_size*0.5)';

vMaxXaxis = '((256*pow(2,((var_zoom)-1)))+((var_mid_long)*((256*pow(2,(var_zoom)))/360))+(def_map_size*0.5))';

vMinYaxis = '((256*pow(2,((var_zoom)-1)))+((0.5*log((1+(sin((var_mid_lat)*pi()/180)))/(1-(sin((var_mid_lat)*pi()/180)))))*((-256*pow(2,(var_zoom)))/(2*pi())))+(def_map_size*0.5))';

vMaxYaxis = '((256*pow(2,((var_zoom)-1)))+((0.5*log((1+(sin((var_mid_lat)*pi()/180)))/(1-(sin((var_mid_lat)*pi()/180)))))*((-256*pow(2,(var_zoom)))/(2*pi())))-(def_map_size*0.5))';

SET HidePrefix='_' ;

// Field required for calcualting best zoom level

_zoom_level:

Load RecNo( ) as _zoom_level autogenerate(max_zoom_level);

//inline load for various map types

maptype:

LOAD * INLINE [

    maptype

    roadmap

  mobile

  satellite

  terrain

  hybrid

];

In the Numbers part of the map, I have this in the dynamic image section:

='http://maps.googleapis.com/maps/api/staticmap?center=' & 

num(var_mid_lat, '##############', '.', ',' )   &  ','  & 

num(var_mid_long, '##############', '.', ',' )   & 

'&zoom='& $(var_zoom) &

'&maptype='& (var_maptype) &

'&size=400x400' & 

'&sensor=false'

and I have the map in focus in each axis max/min:

(256*pow(2,($(var_zoom)-1)))+( var_mid_long  *((256*pow(2,$(var_zoom)))/360)) -round(map_size_x/2)

Is there anything in the map that I'm missing that will help focus the data to the correct lat/lon?

Thanks

Neal

0 Replies