“Wie man sich in Flattern befindet” Code-Antworten

Strömungsort in Flattern

import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';

void main() => runApp(MapScreen());

class MapScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "Map",
      home: MapActivity(),
    );
  }
}

class MapActivity extends StatefulWidget {
  @override
  _MapActivityState createState() => _MapActivityState();
}

class _MapActivityState extends State<MapActivity> {
  LatLng _center ;
  Position currentLocation;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getUserLocation();
  }

 Future<Position> locateUser() async {
    return Geolocator()
        .getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
  }

  getUserLocation() async {
    currentLocation = await locateUser();
    setState(() {
      _center = LatLng(currentLocation.latitude, currentLocation.longitude);
    });
    print('center $_center');
  }
}
Modern Mantis

Wie man sich in Flattern befindet

 add these in android/app/main/AndroidManifest.xml

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
//------------------------------------------------------------
import 'package:http/http.dart' as http;
//------------------------------------------------------------
void getData() async {
    Uri url = Uri.parse(
        'https://api.openweathermap.org/data/2.5/weather?lat=55&lon=180&appid=YOUR_API_KEY');
    http.Response response = await http.get(url);
    print(response.body);
  }
 
  @override
  Widget build(BuildContext context) {
    getData();
 
    return Scaffold(
      body: Container(),
    );
  }
//--------------------------------------------------------- 
  // you can get IPA key form OpenWeather
  //https://openweathermap.org/current
CodeFather

Ähnliche Antworten wie “Wie man sich in Flattern befindet”

Fragen ähnlich wie “Wie man sich in Flattern befindet”

Weitere verwandte Antworten zu “Wie man sich in Flattern befindet” auf Dart

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen