-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlocation.cpp
33 lines (27 loc) · 883 Bytes
/
location.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <Arduino.h>
#include <esp_wifi_location.h>
#define LOCATION_GOOGLE_KEY "INSERT YOUR GOOGLE API KEY HERE"
void setup()
{
//Starting serial for debugging purposes
Serial.begin(115200);
//Connecting to WiFi
WiFi.begin("INSERT_YOUR_SSID_HERE", "INSERT_YOUR_PASS_HERE");
while (WiFi.isConnected() == false) {
delay(500);
Serial.print(".");
}
//Getting location...
Serial.println("Connected, getting location...");
double lat, lng, acc;
esp_wifi_location location(LOCATION_GOOGLE_KEY);
// location.setGoogleKey(LOCATION_GOOGLE_KEY); //You can also change your google key here
// location.setClient(client); You can change the client if you wish (should be a secure client)
if (location.getLocation(lat, lng, acc) == true)
Serial.printf("Location success: %.6f, %.6f (%.2fm)\n", lat, lng, acc);
else
Serial.println("Location failed");
}
void loop()
{
}