gpt4 book ai didi

Google maps showing wrong current location in flutter app(谷歌地图在颤动应用程序中显示错误的当前位置)

转载 作者:bug小助手 更新时间:2023-10-25 10:18:40 26 4
gpt4 key购买 nike



I have added Google maps to my flutter app and I am trying to hive it initialize to my current location. When I open the map page the current location is in Mountainview California but I live in Florida.

我已经将谷歌地图添加到我的Ffltter应用程序中,我正试图将其初始化到我当前的位置。当我打开地图页面时,当前位置是加利福尼亚州的山景城,但我住在佛罗里达州。


Why is this happening?

为什么会发生这种事?


Here is the code I am using and it works except for the current location:

以下是我正在使用的代码,除了当前位置外,它可以正常工作:


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

class MapPropertySearchResults extends StatefulWidget {
const MapPropertySearchResults({super.key});

@override
State<MapPropertySearchResults> createState() =>
_MapPropertySearchResultsState();
}

class _MapPropertySearchResultsState extends State<MapPropertySearchResults> {
late GoogleMapController mapController;

late LatLng _currentPosition;
bool _isLoading = true;

@override
void initState() {
super.initState();
getLocation();
}

getLocation() async {
LocationPermission permission;
permission = await Geolocator.requestPermission();

Position position = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.high);
double lat = position.latitude;
double long = position.longitude;

LatLng location = LatLng(lat, long);

setState(() {
_currentPosition = location;
_isLoading = false;
});
}

void _onMapCreated(GoogleMapController controller) {
mapController = controller;
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Map'),
),
body: _isLoading ?
const Center(child:CircularProgressIndicator()) :
GoogleMap(
onMapCreated: _onMapCreated,
initialCameraPosition: CameraPosition(
target: _currentPosition,
zoom: 16.0,
),
),
);
}
}

Could it be a setting on my computer?
Thanks

这可能是我电脑上的设置吗?谢谢


更多回答

Are you running this on the Android Emulator?

你是在Android模拟器上运行这个程序吗?

The Android emulator have a functionality where you can change the mock location.

Android模拟器有一个功能,您可以在其中更改模拟位置。

优秀答案推荐

Do you use an android simulator? If you do, that's standard practice since it replicates Google's headquarters location

你用安卓模拟器吗?如果你这样做了,这是标准做法,因为它复制了谷歌总部的位置


Alternatively, on iOS, the default location of the iOS simulator is "1 Stockton St, San Francisco, 94108, United States"

或者,在iOS上,iOS模拟器的默认位置是“美国旧金山斯托克顿街1号,邮编:94108”


更多回答

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com