“cara mendapatkan lokasi cruttnt di flutter” Kode Jawaban

Lokasi Currunt di Flutter

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

cara mendapatkan lokasi cruttnt di flutter

 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

Jawaban yang mirip dengan “cara mendapatkan lokasi cruttnt di flutter”

Pertanyaan yang mirip dengan “cara mendapatkan lokasi cruttnt di flutter”

Lebih banyak jawaban terkait untuk “cara mendapatkan lokasi cruttnt di flutter” di Dart

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya