Gps stream to google maps

Hi

I am trying to stream my gps data to google maps. Every five minutes I want to add the location to the map. Any help will be deeply appreciated.

@Costas @Dmitriy @Pavel @Lichtsignaal @Jamin

Thanks in advance :slight_smile:

1 Like

@KAUSTUBHAGARWAL what have you tried so far and do you have any sample code?

Presumably there is an API for Google Maps so perhaps:

GPS Stream Widget is called every 5 minutes and data displayed with Value Display Widget
Then Webhook widget uses the data to update the API.

I haven’t done anything yet. I was thinking whether the GPS stream widget will show value even if i don’t add any hardware since it takes values from the mobile phone?

If your phone has GPS then yes the widget will work.

Okay. How can I publish the data to google maps or to a server like pubnub?

@Costas

It will be separate widget. Right now I don’t see an easy way to integrate Blynk with map.

Okay Dmitry. Eagerly waiting for it. Can you help me in just sending the gps values from the widget to google maps or any other server?

Do we have a widget which can show the location in text(as in name of place) rather than lat/long?

@Dmitriy

Are you saying GPS stream widget can’t currently be used with Webhook widget to update the Google Map API?

It can. However I don’t think this is easy way :slight_smile:.

No but in theory by using the reverse geocoding request and response (address lookup) of Google Maps Geocoding API it should be possible.

Once you have a key the url syntax is:

https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&key=YOUR_KEY

So by using 2 array values of a Value Display widget the body of the Webhook would be something like:
{“latlng”:“/pin[0]/”,“key”:“/pin[1]/”}

ensuring that latlng is in the same format as “40.714224,-73.961452”.

So what would be the procedure like?

I have the location in gps stream widget, after that a webhook to the Google maps api which updates my other two value display with lat and long?

The procedure is to familiarise yourself with the Webhook widget and study the API’s you want to use in detail.

Then it is as per my earlier posts, GPS stream to value display array, array used in Webhook.

The example I provided isn’t perhaps very good as the json data is around 19000 characters but most API’s have different calls that produce smaller data files.

As an example using the same API I referred to earlier but using the following basic syntax of:

https://maps.googleapis.com/maps/api/geocode/json?address=Winnetka&key=YOUR_KEY

the correct coding will produce a json data stream of around 2000 characters.

With some trial and error I knocked up some code that contains the following:

#define BLYNK_MAX_READBYTES 2800  // maximum json size

BLYNK_WRITE(V16){   // Value Display Widget for  Webhook
  String webhookdata = param.asStr();
  yield();
  if((webhookdata.length() > 1) && (webhookdata.length() < 2800)){ 
    Serial.println(webhookdata);
    Serial.print("Data size: ");
    Serial.println(webhookdata.length()); 
    terminal.println(webhookdata);
    terminal.print("Data size: ");
    terminal.println(webhookdata.length());
    terminal.flush(); 
  }
  webhookdata = "";
  yield();
}

BLYNK_WRITE(V17){ // button to trigger API
  int V17btn = param.asInt(); 
  if(V17btn ==  1){
    String API_Element = "Winnetka";    // this is address used in API
    String API_Key = "Your_Google_Key";  // Your Key from Google
    Blynk.virtualWrite(V16, API_Element, API_Key);  // now unlimited number of variables
  }
}

Webhook tied to V16, set as POST, type application/json and url of:

https://maps.googleapis.com/maps/api//geocode/json?address=/pin[0]/&key=/pin[1]/

Body as:

{“address”:"/pin[0]/",key":/pin[1]/}

I’m not entirely sure how the pin array elements should be used in the url and body but currently having them in both works ok whereas in one or the other doesn’t work.

Sketch produces the following in Serial Monitor

{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "Winnetka",
               "short_name" : "Winnetka",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "New Trier Township",
               "short_name" : "New Trier Township",
               "types" : [ "administrative_area_level_3", "political" ]
            },
            {
               "long_name" : "Cook County",
               "short_name" : "Cook County",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "Illinois",
               "short_name" : "IL",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "United States",
               "short_name" : "US",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Winnetka, IL, USA",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 42.1282269,
                  "lng" : -87.71080979999999
               },
               "southwest" : {
                  "lat" : 42.0886089,
                  "lng" : -87.7708629
               }
            },
            "location" : {
               "lat" : 42.10808340000001,
               "lng" : -87.735895
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 42.1282269,
                  "lng" : -87.7108162
               },
               "southwest" : {
                  "lat" : 42.0886089,
                  "lng" : -87.7708629
               }
            }
         },
         "place_id" : "ChIJW8Va5TnED4gRY91Ng47qy3Q",
         "types" : [ "locality", "political" ]
      }
   ],
   "status" : "OK"
}

Data size: 1944

Procedure then is to parse the data, but for sending longitude and latitude to an actual Google Map you would just be looking for confirmation in the json data that Google had accepted the data you sent them.

This is just an example of the basics of using some of Google’s location based API’s.

Suppose i have the gps stream widget on V10

I want to display the data on display value widgets like- Latitude on V11 , Longitude on V12.

I want to send this data to another 3rd party url like thingspeak. What would that would be like?

No provision for including headers?

@KAUSTUBHAGARWAL you can send the details to whatever virtual pins you like for visual display purposes but in addition you need to also send them to the pin tied to the Webhook in array format.

It it different for each API but even if you hardcode your API key in the Webhook you will normally need an array of at least 2 variables to cover longitude and latitude. Webhook can’t take the details from more than 1 pin, hence in your V10 (GPS Stream) you would have something like:

Blynk.virtualWrite(V13, API_longitude, API_latitude); // V13 being used in Webhook

This sets up an array of pin[0] and pin[1] to use in Webhook as per my earlier posts.

It is possible with some API’s to combine longitude and latitude into a single String variable but even done this way the full String must appear in a single virtual pin value display. You can hide the value display on an used TAB if you wish but it must exist.

A further look at Google’s Geocoding API now allows the submission of longitude and latitude to return a manageable 2000 character json data file.

Providing you know a bit about how Google Maps works it will confirm for example location details in Brooklyn NY or Paralimni CY etc.

Can you please share one example also about Google Geolocation API?
How can I use the following POST request with Arduino Yun and the Blynk app?

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

BLYNK_WRITE(V16){   // Value Display Widget for  Webhook
  String webhookdata = param.asStr();
  Serial.println(webhookdata);
  yield();
  if((webhookdata.length() >= 1) && (webhookdata.length() < 1024)){ 
    Serial.println("WebHook data:");
    Serial.println(webhookdata);
    Serial.print("Data size: ");
    Serial.println(webhookdata.length()); 
    terminal.flush(); 
  }
  webhookdata = "";
  yield();
}

BLYNK_WRITE(V17){ // button to trigger API
  int V17btn = param.asInt(); 
  if(V17btn ==  1){
    terminal.println("API........");
    terminal.flush(); 
    Blynk.virtualWrite(V16,"https://www.googleapis.com/geolocation/v1/geolocate?key=6BAIzaSyAhUm9NoXKyXwgSzphn009rXmf5V17kcrkj");
    //Blynk.virtualWrite(V16, "https://raw.githubusercontent.com/blynkkk/blynk-library/master/extras/logo.txt");
  }
}

This code doesnt work for me :frowning:
Any help is appreciated…

Are GPS widgets supported in iOS? I am not able to add any GPS widgets in my iPhone Blynk app.
Please let me know how I can ask GPS data with Arduino Yun board from Blynk app.
Does anybody have ideas?

Not yet. And pretty sure they will be a way off.

Any news on an IoS update? Seems we have quite a lot of excellent functionality on the Android side, but IoS still lacks the advanced functions (e.g., sensors, map, video) that would make Blynk on iPhone compelling. Thanks in advance for info on new functions or schedule of releases (and maybe an “A” or “I” in the docs so that we know in advance which widgets/functions work with which device) so that we can plan accordingly.

Follow this topic New iOS Release 2.8.4