Home » Developing U++ » UppHub » Using GoogleMaps from U++
Using GoogleMaps from U++ [message #24774] |
Fri, 29 January 2010 16:23 |
|
mirek
Messages: 13975 Registered: November 2005
|
Ultimate Member |
|
|
Not sure where to put this, but I need it for my work and I guess it would be interesting for others:
#include <CtrlLib/CtrlLib.h>
#include <Web/Web.h>
using namespace Upp;
#define LLOG(x) LOG(x)
String apikey = "";
void SetGoogleMapsKey(const char *key)
{
apikey = key;
}
String GetGoogleMap(double center_x, double center_y, int zoom, int cx, int cy,
const char *format = "png", String *error = NULL)
{
String request;
request << "http://maps.google.com/maps/api/staticmap?center=" <<
AsString(center_x) << ',' << AsString(center_y) <<
"&zoom=" << zoom <<
"&size=" << cx << 'x' << cy <<
"&format=" << format <<
"&sensor=false&key=" << apikey;
LLOG(request);
return HttpClientGet(request, NULL, error);
}
Image GetGoogleMapImage(double center_x, double center_y, int zoom, int cx, int cy,
const char *format = "png", String *error = NULL)
{
return StreamRaster::LoadStringAny(GetGoogleMap(center_x, center_y, zoom, cx, cy, format, error));
}
struct App : public TopWindow {
virtual void Paint(Draw& w) {
Size sz = GetSize();
String error;
w.DrawRect(sz, SColorPaper());
Image m = GetGoogleMapImage(40.714728, -73.998672, 15, 640, 640, "png", &error);
if(IsNull(m))
w.DrawText(0, 0, error);
else
w.DrawImage(0, 0, m);
}
};
GUI_APP_MAIN
{
SetGoogleMapsKey(/* put your API key here */);
App().Run();
}
|
|
|
Goto Forum:
Current Time: Thu Apr 18 13:06:17 CEST 2024
Total time taken to generate the page: 0.01988 seconds
|