-
Notifications
You must be signed in to change notification settings - Fork 2
/
getLocation.dart
67 lines (61 loc) · 1.88 KB
/
getLocation.dart
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// ignore_for_file: prefer_const_constructors
import 'package:clima/DrawerPage.dart';
import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'package:flutter_spinkit/flutter_spinkit.dart';
class Location {
static double latitude = 0, longitude = 0;
final String key = 'b88705431322742c3310ab889a1501ae';
Future<void> getCurrentLocation() async {
Position? position;
try {
position = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.high,
);
} catch (e) {
print('error in getting the position co-ordinates');
}
print(position);
latitude = position?.latitude ?? 0;
longitude = position?.longitude ?? 0;
print(latitude);
print(longitude);
}
void getData() async {
http.Response response = await http.get(
Uri.parse(
'https://api.openweathermap.org/data/2.5/weather?lat=$latitude&lon=$longitude&appid=$key', // assign variables to key, lat, lon
),
);
if (response.statusCode == 200) {
var decodedData = jsonDecode(response.body);
// var weatherDescription =
// jsonDecode(response.body)['weather'][0]['description'];
var weatherDescription = decodedData['weather'][0]['description'];
print(weatherDescription);
// print(response.body);
} else {
print(response.statusCode);
}
}
}
class Animation extends StatefulWidget {
@override
State<Animation> createState() => _AnimationState();
}
class _AnimationState extends State<Animation> {
var spinkit;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: SpinKitRotatingCircle(
color: Colors.white,
size: 50.0,
),
),
);
}
}