configuration property for google_api_key
Added by Pedro Vicente over 7 years ago
the documentation for WGoogleMap
https://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1WGoogleMap.html
says
"To use the map on a public server you will need to obtain a key. The widget will look for this key as the configuration property "google_api_key\".
how can this be done, to read the configuration property?
Replies (11)
RE: configuration property for google_api_key - Added by Pedro Vicente over 7 years ago
I found this post that explains how to do it
http://redmine.webtoolkit.eu/boards/2/topics/13436?r=13511#message-13511
so, I defined this file wt_config.xml ("aaa----google----key") not real key
<server>
<application-settings location="*">
<properties>
<property name="google_api_key">aaa---google---key</property>
</properties>
</application-settings>
</server>
and run it like
./map.wt ---http-address=0.0.0.0 ---http-port=8080 ---docroot=. -c ../../../examples/map/wt_config.xml
but I still have an error on obtaining the key,
Oops! Something went wrong.
This page didn't load Google Maps correctly. See the JavaScript console for technical details.
, the JavaScript console says
"Google Maps API warning: NoApiKeys https://developers.google.com/maps/documentation/javascript/error-messages#no-api-keys" util.js:216:33
"Google Maps API warning: SensorNotRequired https://developers.google.com/maps/documentation/javascript/error-messages#sensor-not-required" util.js:216:33
"Google Maps API error: MissingKeyMapError https://developers.google.com/maps/documentation/javascript/error-messages#missing-key-map-error"
as explained here
https://churchthemes.com/page-didnt-load-google-maps-correctly/#MissingKeyMapError
I obtained a new key
but the error still happens
Going into the Visual Studio debugger on the Windows version (I am running on linux the version that gives the error) , the key is read correctly in
Wt::WApplication::readConfigurationProperty("google_api_key", googlekey);
any ideas?
RE: configuration property for google_api_key - Added by Pedro Vicente over 7 years ago
I modified to code in WGoogleMap to print the key
[2017-Aug-07 15:00:35.019459] 2432 [/ diNeFepo8slezMko] [info] "WGoogleMap: googlekey: ABQIAAAAWqrN5o4-ISwj0Up_depYvhTwM0brOpm-All5BF6PoaKBxRWWERS-S9gPtCri-B6BZeXV8KpT4F80DQ"
[2017-Aug-07 15:00:35.019538] 2432 [/ diNeFepo8slezMko] [info] "WGoogleMap: googlekey: MYKEY"
the code reads the correct key, so I'm of options
this seems like a WGoogleMap bug, but the samples on the Wt web site show a functional WGoogleMap example
RE: configuration property for google_api_key - Added by Wim Dumon over 7 years ago
Pedro,
Are you using one of the most recent Wt version?
Wim.
RE: configuration property for google_api_key - Added by Pedro Vicente over 7 years ago
I am using wt-3.3.8-rc2.
Was there any change in WGoogleMap in the the 4.0 version?
RE: configuration property for google_api_key - Added by Wim Dumon over 7 years ago
No.
Can you check that your browser sends the correct request including the api key to the google api loader?
Wim.
RE: configuration property for google_api_key - Added by Pedro Vicente over 7 years ago
Wim
I am am going to post a series of posts that will help you debug this, but my first question is:
how can I check if the browser sends the correct request including the api key?
also, this is not critical for me now, because I decided to do my own WT map library based on Leaflet.js, the main reason being because of this issue, and also the WGoogleMap does not have a function for polygons, and that is really all I need.
So, I am using
1) wt-3.3.8-rc2
2) Visual Studio 2015 on Windows 10
3) Firefox browser
The map is displayed when I run on localhost 127.0.0.1:8080 with
./map.wt --http-address=0.0.0.0 --http-port=8080 --docroot=. -c ../../../examples/map/wt_config.xml
RE: configuration property for google_api_key - Added by Pedro Vicente over 7 years ago
my program is
#include <Wt/WApplication>
#include <Wt/WText>
#include <Wt/WCheckBox>
#include <Wt/WComboBox>
#include <Wt/WContainerWidget>
#include <Wt/WHBoxLayout>
#include <Wt/WGoogleMap>
#include <Wt/WLeaflet.hh>
#include <Wt/WPushButton>
#include <Wt/WStringListModel>
#include <Wt/WTemplate>
#if 1
#define USE_GOOGLE_MAP
#endif
//run
//./map.wt --http-address=0.0.0.0 --http-port=8080 --docroot=. -c ../../../examples/map/wt_config.xml
///////////////////////////////////////////////////////////////////////////////////////
//MapApplication
///////////////////////////////////////////////////////////////////////////////////////
class MapApplication : public Wt::WApplication
{
public:
Wt::WText* m_msg;
Wt::WGoogleMap *m_map;
Wt::WLeaflet *m_leaflet;
MapApplication(const Wt::WEnvironment& env) : Wt::WApplication(env)
{
setTitle("Map");
m_msg = new Wt::WText("Map engine");
root()->addWidget(m_msg);
#ifdef USE_GOOGLE_MAP
m_map = new Wt::WGoogleMap(Wt::WGoogleMap::Version3);
Wt::WGoogleMap::Coordinate center(38.9072, -77.0369);
m_map->setCenter(center);
m_map->setHeight(200);
m_map->disableScrollWheelZoom();
m_map->disableDoubleClickZoom();
std::vector<Wt::WGoogleMap::Coordinate> polygon;
polygon.push_back(Wt::WGoogleMap::Coordinate(38.9072, -77.0369));
polygon.push_back(Wt::WGoogleMap::Coordinate(38.9100, -77.0369));
polygon.push_back(Wt::WGoogleMap::Coordinate(38.9072, -77.1000));
m_map->addPolyline(polygon, Wt::WColor(202, 81, 0));
root()->addWidget(m_map);
#else
m_leaflet = new Wt::WLeaflet();
root()->addWidget(m_leaflet);
#endif
}
};
///////////////////////////////////////////////////////////////////////////////////////
//main
///////////////////////////////////////////////////////////////////////////////////////
Wt::WApplication* create_application(const Wt::WEnvironment& env)
{
return new MapApplication(env);
}
int main(int argc, char** argv)
{
return Wt::WRun(argc, argv, &create_application);
}
RE: configuration property for google_api_key - Added by Pedro Vicente over 7 years ago
I modified WGoogleMap.C to print out the key:
void WGoogleMap::render(WFlags<RenderFlag> flags)
{
if (flags & RenderFull) {
WApplication *app = WApplication::instance();
std::string googlekey = localhost_key;
LOG_INFO("googlekey: " << googlekey);
Wt::WApplication::readConfigurationProperty("google_api_key", googlekey);
LOG_INFO("googlekey: " << googlekey);
RE: configuration property for google_api_key - Added by Pedro Vicente over 7 years ago
and this is the output on my localhost terminal (I blanked my key)
as you can see it loads the WT default key, then reads my key from the config file
127.0.0.1 - - [2017-Aug-17 12:58:36.415962] "GET /?wtd=uKXdAXoeRwaP2pxy&request=style&page=1 HTTP/1.1" 200 96
[2017-Aug-17 12:58:36.415962] 12360 - [info] "WebRequest: took 84.223ms"
[2017-Aug-17 12:58:36.415962] 12360 [/ uKXdAXoeRwaP2pxy] [info] "WGoogleMap: googlekey: ABQIAAAAWqrN5o4-ISwj0Up_depYvhTwM0brOpm-All5BF6PoaKBxRWWERS-S9gPtCri-B6BZeXV8KpT4F80DQ"
[2017-Aug-17 12:58:36.431589] 12360 [/ uKXdAXoeRwaP2pxy] [info] "WGoogleMap: googlekey: AI--------------------------I"
"GET /resources/themes/default/wt.css HTTP/1.1" 304 0
127.0.0.1 - - [2017-Aug-17 12:58:36.453736] "GET /?wtd=uKXdAXoeRwaP2pxy&sid=-1980974992&webGL=true&scrW=1280&scrH=720&tz=-240&htmlHistory=true&deployPath=%2F&request=script&rand=856111364 HTTP/1.1" 200 113892
RE: configuration property for google_api_key - Added by Pedro Vicente over 7 years ago
when I ran on a internet host (e.g http://1.2.3.4:8080/) running the same program on Linux Ubuntu and Firefox browser, what happens is
1) map is displayed on browser for a second or two
2) then I get this message on the browser
Oops! Something went wrong.
This page didn't load Google Maps correctly. See the JavaScript console for technical details.
and the browser console has this log
<?xml-stylesheet?> processing instruction does not have any effect outside the prolog anymore (see bug 360119). dstocks2.xul
Failed to execute ‘postMessage’ on ‘DOMWindow’: The target origin provided (‘https://www.google.com’) does not match the recipient window’s origin (‘http://127.0.0.1:8080’). www.google.com
"Google Maps API warning: NoApiKeys https://developers.google.com/maps/documentation/javascript/error-messages#no-api-keys" util.js:222:12
"Google Maps API warning: SensorNotRequired https://developers.google.com/maps/documentation/javascript/error-messages#sensor-not-required" util.js:222:12
Invalid chrome URI: /Key event not available on some keyboard layouts: key=“r” modifiers=“accel,alt” id=“key_toggleReaderMode” browser.xul
Key event not available on some keyboard layouts: key=“i” modifiers=“accel,alt,shift” id=“key_browserToolbox” browser.xul
1502989413381 extensions.shield-recipe-client.recipe-runner ERROR Error checking filter for "Shield Study 15 - Containers (Bug 1382270)" Log.jsm:748
1502989413381 extensions.shield-recipe-client.recipe-runner ERROR Filter: "(
[normandy.userId]|bucketSample(460, 20, 1000)
&& normandy.locale in ['en-US', 'en-AU', 'en-CA', 'en-GB', 'en-NZ', 'en-ZA']
&& normandy.channel == 'release'
&& normandy.version >= '53.0'
&& 'privacy.userContext.enabled'|preferenceIsUserSet == false
&& 'privacy.userContext.enabled'|preferenceValue == false
&& !normandy.isFirstRun
)" Log.jsm:748
1502989413382 extensions.shield-recipe-client.recipe-runner ERROR Error: "Error: Transform 'preferenceValue' is not defined." Log.jsm:748
Use of getPreventDefault() is deprecated. Use defaultPrevented instead. jquery-1.7.2-ui-1.8.21-ujs-2.0.3.js:3:7108
"Google Maps API error: MissingKeyMapError https://developers.google.com/maps/documentation/javascript/error-messages#missing-key-map-error" js:38:315
"Google Maps API warning: NoApiKeys https://developers.google.com/maps/documentation/javascript/error-messages#no-api-keys" util.js:222:12
"Google Maps API warning: SensorNotRequired https://developers.google.com/maps/documentation/javascript/error-messages#sensor-not-required" util.js:222:12
<?xml-stylesheet?> processing instruction does not have any effect outside the prolog anymore (see bug 360119). dstocks2.xul
RE: configuration property for google_api_key - Added by Pedro Vicente over 7 years ago
The WT output on the Linux terminal is: (note that WT loaded the Google Key as before)
[2017-Aug-17 13:28:04.176243] 13480 - [info] "Wt: session created (#sessions = 2)"
[2017-Aug-17 13:28:04.176395] 13480 [/ 8KOTuXe7nN3Va9L6] [info] "WEnvironment: UserAgent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0"
140.90.40.1 - - [2017-Aug-17 13:28:04.177448] "GET / HTTP/1.1" 200 4690
[2017-Aug-17 13:28:04.177535] 13480 - [info] "WebRequest: took 1.45ms"
[2017-Aug-17 13:28:04.266806] 13480 - [info] "WebController: Removing session nj5FQuRnBpOlOk8s"
140.90.40.1 - - [2017-Aug-17 13:28:04.267036] "POST /?wtd=nj5FQuRnBpOlOk8s HTTP/1.1" 200 123
[2017-Aug-17 13:28:04.267147] 13480 - [info] "WebRequest: took 0.666ms"
[2017-Aug-17 13:28:04.267173] 13480 [/ nj5FQuRnBpOlOk8s] [info] "Wt: session destroyed (#sessions = 1)"
[2017-Aug-17 13:28:04.356383] 13480 [/ 8KOTuXe7nN3Va9L6] [info] "WGoogleMap: googlekey: ABQIAAAAWqrN5o4-ISwj0Up_depYvhTwM0brOpm-All5BF6PoaKBxRWWERS-S9gPtCri-B6BZeXV8KpT4F80DQ"
[2017-Aug-17 13:28:04.356498] 13480 [/ 8KOTuXe7nN3Va9L6] [info] "WGoogleMap: googlekey: AI------------------------------IX6gI"
140.90.40.1 - - [2017-Aug-17 13:28:04.356882] "GET /?wtd=8KOTuXe7nN3Va9L6&request=style&page=1 HTTP/1.1" 200 0
140.90.40.1 - - [2017-Aug-17 13:28:04.356888] "GET /?wtd=8KOTuXe7nN3Va9L6&sid=324426812&webGL=true&scrW=1280&scrH=720&tz=-240&htmlHistory=true&deployPath=%2F&request=script&rand=2174298546 HTTP/1.1" 200 114020