前提・実現したいこと
geolocationを用いて、現在地の緯度経度を取得しようとしています。
エラーを読んだ限りデバイスの許可が出ていないということを把握しました。
そのため、ドキュメント通りにios,androidのinfo.splitなどに記載しましたが解決しません。
発生している問題・エラーメッセージ
[VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: User denied permissions to access the device's location. #0 MethodChannelGeolocator.getCurrentPosition (package:geolocator_platform_interface/src/implementations/method_channel_geolocator.dart:127:7) <asynchronous suspension> #1 _MyHomePageState.getLocation (package:applicationname/main.dart:37:25) <asynchronous suspension>
該当のソースコード
とりあえず、geolocationから緯度経度を取得するようにしています。
//main.dart import 'package:flutter/material.dart'; import 'package:geolocator/geolocator.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key); // This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( primarySwatch: Colors.blue, ), home: const MyHomePage(title: 'Flutter Demo Home Page'), ); } } class MyHomePage extends StatefulWidget { const MyHomePage({Key? key, required this.title}) : super(key: key); final String title; @override State<MyHomePage> createState() => _MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> { String _location = "no data"; Future<void> getLocation() async { // 現在の位置を返す Position position = await Geolocator.getCurrentPosition( desiredAccuracy: LocationAccuracy.high); setState(() { _location = position.toString(); }); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(_location), ), body: Center( // Center is a layout widget. It takes a single child and positions it // in the middle of the parent. child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ const Text( 'You have pushed the button this many times:', ), Text( '_location', style: Theme.of(context).textTheme.headline4, ), ], ), ), floatingActionButton: FloatingActionButton( onPressed: getLocation, child: Icon(Icons.location_on)), ); } }
info.split
1<?xml version="1.0" encoding="UTF-8"?> 2<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 3<plist version="1.0"> 4<dict> 5 <key>NSLocationWhenInUseUsageDescription</key> 6 <string>This app needs access to location when open.</string> 7 <key>NSLocationAlwaysUsageDescription</key> 8 <string>This app needs access to location when in the background.</string> 9 <key>CFBundleDevelopmentRegion</key> 10 <string>$(DEVELOPMENT_LANGUAGE)</string> 11 <key>CFBundleDisplayName</key> 12 <string>applicationname</string> 13 <key>CFBundleExecutable</key> 14 <string>$(EXECUTABLE_NAME)</string> 15 <key>CFBundleIdentifier</key> 16 <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> 17 <key>CFBundleInfoDictionaryVersion</key> 18 <string>6.0</string> 19 <key>CFBundleName</key> 20 <string>applicationname</string> 21 <key>CFBundlePackageType</key> 22 <string>APPL</string> 23 <key>CFBundleShortVersionString</key> 24 <string>$(FLUTTER_BUILD_NAME)</string> 25 <key>CFBundleSignature</key> 26 <string>????</string> 27 <key>CFBundleVersion</key> 28 <string>$(FLUTTER_BUILD_NUMBER)</string> 29 <key>LSRequiresIPhoneOS</key> 30 <true/> 31 <key>UILaunchStoryboardName</key> 32 <string>LaunchScreen</string> 33 <key>UIMainStoryboardFile</key> 34 <string>Main</string> 35 <key>UISupportedInterfaceOrientations</key> 36 <array> 37 <string>UIInterfaceOrientationPortrait</string> 38 <string>UIInterfaceOrientationLandscapeLeft</string> 39 <string>UIInterfaceOrientationLandscapeRight</string> 40 </array> 41 <key>UISupportedInterfaceOrientations~ipad</key> 42 <array> 43 <string>UIInterfaceOrientationPortrait</string> 44 <string>UIInterfaceOrientationPortraitUpsideDown</string> 45 <string>UIInterfaceOrientationLandscapeLeft</string> 46 <string>UIInterfaceOrientationLandscapeRight</string> 47 </array> 48 <key>UIViewControllerBasedStatusBarAppearance</key> 49 <true/> 50</dict> 51</plist> 52
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。