I want to call API but I can't give latitude and longitude as variables.
Asked
Active
Viewed 363 times
0

griffins
- 7,079
- 4
- 29
- 54

Shamil Keheliya
- 358
- 3
- 7
-
in the future post code snippets – griffins May 17 '21 at 18:09
3 Answers
0
basically you would want to define your uri in the getData
method.
example:
getData({String latitude,String longitude})async{
..define uri. var url =Uri.https..
http.Response..

griffins
- 7,079
- 4
- 29
- 54
0
As griffin said to write url in getData function, so do that and also Extract and pass the query parameters like this in that function
void getData(double latitude,double longitude) async {
Map<String, dynamic> param = {
'longitude': longitude,
'latitude': latitude,
};
var url = Uri.https('api/openweathermap.org',
'/data/2.5/weather',
param);
}

Daniyal Dolare
- 401
- 3
- 9
0
Create a function instead of variable
Uri url(double latitude, double longitude) {
return Uri.https('api.abc.org', 'data/123/abc', {
'lat': latitude,
'lon': longitude,
});
}
Future<void> getData(double latitude, double longitude) async {
final response = await http.get(url(latitude, longitude));
}

Hemal Moradiya
- 1,715
- 1
- 6
- 26