Get the location info from Google API and Show location on Map widget

Dear All,

Can you please help me with getting the location information from Google Geolocation API and Show location on Map widget in the Blynk app?

I am using Arduino Yun with iOS Blynk app.

https://www.googleapis.com/geolocation/v1/geolocate?key=YOUR_API_KEY

#define BLYNK_PRINT Serial

#define BLYNK_MAX_READBYTES 4096

#include <Bridge.h>
#include <BlynkSimpleYun.h>


char auth[] = "4730d34a23444444818656b8424399b95a";

WidgetTerminal terminal(V1);

BLYNK_WRITE(V17)
{
    String webhookdata = param.asStr();
    yield();
   if((webhookdata.length() > 1) && (webhookdata.length() < 4096)){ 

  Serial.println("WebHook data:");
  Serial.println(param.asStr());
  Serial.print("Data size: ");
  Serial.println(webhookdata.length()); 
    terminal.println(webhookdata);
    terminal.print("Data size: ");
    terminal.println(webhookdata.length());
    terminal.flush(); 
    webhookdata = "";
    yield();
   }
    
    else{}
    Serial.println("Unknown problem");
    terminal.print("Unknown problem");
     Serial.println(webhookdata);
     Serial.println(webhookdata.length());
    }
          }
        }
            void setup()
            {
              // Debug console
              Serial.begin(9600);

              Blynk.begin(auth);

              // If you want to remove all points:
              //myMap.clear();

              //int index = 1;
              //float lat = 41.9;
              //float lon = 2.2;
              
              myMap.location(index, lat, lon, "value");
            }

            void loop()
            {
              Blynk.run();
            }

I am not sure how to get the webhook data from POST request and to assign lat and lon info to Map widget.

Any help is appreciated…

@devecihalil GET was modified to accept POST requests so I never use POST.

If you are trying to send 4096 character to Terminal you will also need SENDBYTES but with SENDBYTES and READBYTES I have never been able to go above around 2000.

Personally I would forget any attempt to send this to Terminal, use Serial Monitor to start with.

Google json parsing with the Arduinojson library.

I have tried to use both POST and GET.

I removed also Terminal lines and working only with Serial monitor.

Somehow Google geolocation API does not seem to work in this way. I believe it requires Request body containing all Cell Tower objects or wifi access point objects.

I really would like to find a way to get the geolocation data without using any GPS or GSM module.

Do you think maybe is there a way to manage it?

Thanks…

@devecihalil with my own API key and a MAC address of an AP located somewhere in California I was able to get some results with the API. I couldn’t work out how to use the MAC address of my AP or that of my ISP though.

it is also working for me if i make a POST or GET Geolocation request with “Request Body”.

But my aim is to make the request without any cell tower or wifi access point objects. (https://www.googleapis.com/geolocation/v1/geolocate?key=YOUR_API_KEY)

I am trying to understand if it is technically possible. When I try to use any HTTP requester program in the web browser, I can easily get a response without having to use any additional “Request Body”
Something like this:
{
“location”: {
“lat”: 46.9743,
“lng”: 14.2542803
},
“accuracy”: 3956.0
}

I believe that there should be a way to get a similar response only by using Arduino YUN and this API without any additional GSM or GPS shield.

Any help or comment appreciated

Thanks…