如何从iOS中获取用户的当前位置?
我实现了checkPermissionStatus的方法,尽管我收到了一条错误消息,Unhandled Exception: MissingPluginException(在通道 flutter.baseflow.com/permissions/methods 上找不到方法 checkPermissionStatus 的实现)
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:geolocator/geolocator.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:sampletestingpro/Pages/Firstpage.dart';
import 'package:custom_switch/custom_switch.dart';
class Clockinout extends StatefulWidget {
@override
_ClockinoutState createState() => _ClockinoutState();
}
class _ClockinoutState extends State<Clockinout> {
bool location= false;
GoogleMapController _controller;
Position position;
Widget _child;
Future<void> getPermission() async{
PermissionStatus permission=await PermissionHandler()
.checkPermissionStatus(PermissionGroup.location);
if(permission==PermissionStatus.denied)
{
await PermissionHandler()
.requestPermissions([PermissionGroup.locationAlways]);
}
var geolocator=Geolocator();
GeolocationStatus geolocationStatus=await geolocator.checkGeolocationPermissionStatus();
switch(geolocationStatus)
{
case GeolocationStatus.disabled:
showToast('Disabled');
break;
case GeolocationStatus.restricted:
showToast('Restricted');
break;
case GeolocationStatus.denied: …
Run Code Online (Sandbox Code Playgroud) google-maps currentlocation dart android-permissions flutter
我正在使用当前位置图标的自定义调出(标题和副标题).我尝试了以下来禁用默认注释,但它不起作用.
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
{
NSLog(@"viewForAnnotation");
if ([annotation isKindOfClass:[MKUserLocation class]])
{
MKAnnotationView *userLocationView = [mapView viewForAnnotation:annotation];
userLocationView.canShowCallout = NO;
NSLog(@"[annotation isKindOfClass:[MKUserLocation class]");
return nil;
}
}
Run Code Online (Sandbox Code Playgroud)
只有它的工作方式是
-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)ann
{
if([ann.annotation isKindOfClass:[MKUserLocation class]] )
{
[mymap deselectAnnotation:ann.annotation animated:NO];
}
}
Run Code Online (Sandbox Code Playgroud)
但它有时会滞后.是否有其他方法可以禁用当前位置注释的默认标注视图?任何帮助将不胜感激.
我一直在互联网上试图找到如何从这个城市和国家CLGeocoder
.我可以轻松获得经度和纬度,但我需要城市和国家的信息,而且我一直在使用已弃用的方法等等,任何想法?它基本上需要获取位置,然后有一个NSString
国家和一个NSString
城市,所以我可以使用它们查找更多信息或将它们放在标签上等.
我正在使用2013版Google Maps SDK for iOS.我想自定义当前位置的默认蓝点与另一个图标或周围的脉冲圈.
我知道我们可以mapView:viewForAnnotation:
在MKMapView中做到这一点,但我不知道如何使用谷歌地图.
google-maps google-maps-markers ios currentlocation google-maps-sdk-ios
我有一个mapView,使用viewDidLoad
以下内容放大到当前位置:
#define METERS_PER_MILE 1609.344
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
mapView.showsUserLocation=TRUE;
// zoom to a specific area
CLLocationCoordinate2D zoomLocation;
zoomLocation.latitude = -28.994167;
zoomLocation.longitude = 134.866944;
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, 1900*METERS_PER_MILE, 1900*METERS_PER_MILE);
MKCoordinateRegion adjustedRegion = [mapView regionThatFits:viewRegion];
// make sure the Google water mark is always visible
mapView.autoresizingMask =
(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
[mapView setRegion:adjustedRegion animated:YES];
mapView.delegate=self;
searchBar.delegate = self;
}
Run Code Online (Sandbox Code Playgroud)
这很好用.我添加了一个搜索栏和一个跳转到特定地址位置的函数.这也很好.我现在想要添加一个按钮来跳回当前位置.你能帮我一把吗?
干杯
我正在构建一个移动版网站,试图通过一键式链接从用户的当前位置启动谷歌地图,并提供前往业务的行车路线.我认为它适用于iPhone,但在Android上进行测试时,它会查看"当前%20位置"并尝试查找名为"当前位置"的商家.这是我目前的代码:
<a href="http://maps.google.com/maps?saddr=Current%20Location&daddr=123 Street Rd,Cityville,MD,21098">Get Directions</a>
Run Code Online (Sandbox Code Playgroud)
我需要一个通用字符串来搜索当前位置,并且无法在网上找到明确的答案.
在此先感谢您的帮助!
如何获取当前位置的经纬度.
我试过这个.使用Xcode 6.01和IOS SDK 8.0
-(CLLocationCoordinate2D) getLocation{
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startUpdatingLocation];
CLLocation *location = [locationManager location];
CLLocationCoordinate2D coordinate = [location coordinate];
return coordinate;
}
- (void)getCurrentLocation{
CLLocationCoordinate2D coordinate = [self getLocation];
NSString *latitude = [NSString stringWithFormat:@"%f", coordinate.latitude];
NSString *longitude = [NSString stringWithFormat:@"%f", coordinate.longitude];
NSLog(@"Latitude = %@", latitude);
NSLog(@"Longitude = %@", longitude);
}
- (void)viewDidLoad{
[super viewDidLoad];
[self getCurrentLocation];
}
Run Code Online (Sandbox Code Playgroud)
在这里,我将模拟器位置启用到Deployment 8.0 iPhone模拟器4s.即使在设备上也无法正常工作.
@ALL请告诉我,我在这里做错了什么.
core-location cllocationmanager cllocation currentlocation ios8
在以下场景中获取android当前位置的最佳方法是什么,
如果GPS不可用,请从网络提供商处获取位置
如果GPS可用并且可以获得当前位置,请从GPS提供商处获取位置
如果GPS可用但无法获得当前位置(即连续搜索位置),请从网络提供商处获取位置.
现在如果gps不可用,我可以从网络获取位置,我们非常感谢满足上述情况的最佳答案.提前致谢.
currentlocation ×10
google-maps ×4
ios ×4
iphone ×3
android ×2
objective-c ×2
clgeocoder ×1
cllocation ×1
dart ×1
flutter ×1
gps ×1
ios6 ×1
ios8 ×1
mapkit ×1
mkannotation ×1
mobile ×1
nsstring ×1
xcode ×1