You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

282 lines
10 KiB

//
// MapViewController.m
// LekangGuard
//
// Created by ecell on 2022/9/27.
//
#import "MapViewController.h"
#import "GDMapView.h"
#import "GoogleMapView.h"
#import "MarkExplainViewController.h"
#import "ElectronicFenceViewController.h"
#import "TrackViewController.h"
@interface MapViewController ()
@property (nonatomic ,strong) UIView *topView;
/// 定位图片
@property (nonatomic ,weak) UIImageView *mapImg;
/// 定位时间Label
@property (nonatomic ,weak) UILabel *timeLabel;
/// 电量图片
@property (nonatomic ,weak) UIImageView *electricityImg;
/// 电量Label
@property (nonatomic ,weak) UILabel *electricityLabel;
/// 位置
@property (nonatomic ,weak) UILabel *addLabel;
/// 高德地图
@property (nonatomic ,strong) GDMapView *gdMapView;
/// 谷歌地图
@property (nonatomic ,strong) GoogleMapView *googleMapView;
@end
@implementation MapViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.zx_navTitle = GJText(@"定位");
self.view.backgroundColor = KKBackgroundGrey;
[self.view addSubview:self.topView];
[self.view addSubview:self.gdMapView];
[self rightBtns];
[[[NSNotificationCenter defaultCenter] rac_addObserverForName:@"updateBatteryAndLocation" object:nil] subscribeNext:^(NSNotification *x){
[self UpdataLatestlocation:APIManager.sharedManager.deviceModel.imei];
}];
[[[NSNotificationCenter defaultCenter] rac_addObserverForName:@"deviceNowLocation" object:nil] subscribeNext:^(NSNotification *x)
{
[self UpdataLatestlocation:APIManager.sharedManager.deviceModel.imei];
}];
}
- (void)rightBtns
{
NSMutableArray *btnsTitleArr = [NSMutableArray new];
NSMutableArray *btnsImgArr = [NSMutableArray new];
[btnsTitleArr addObject:GJText(@"定位")];
[btnsImgArr addObject:@"icon_location_positioning"];
[btnsTitleArr addObject:GJText(@"历史轨迹")];
[btnsImgArr addObject:@"icon_location_history"];
if (APIManager.sharedManager.deviceModel.electronicFence)
{
[btnsTitleArr addObject:GJText(@"电子围栏")];
[btnsImgArr addObject:@"icon_location_security_fence"];
}
[btnsTitleArr addObject:GJText(@"定位说明")];
[btnsImgArr addObject:@"icon_histroy_g"];
for (int i = 0; i < btnsImgArr.count; i++)
{
NSString *title = [btnsTitleArr objectAtIndex:i];
NSString *image = [btnsImgArr objectAtIndex:i];
UIButton *button = [UICommon ui_buttonSimple:CGRectZero font:FontADA_(8) normalColor:RGB(153, 153, 153) normalText:title click:^(UIButton *btn) {
if ([btn.currentTitle isEqualToString:GJText(@"定位")])
{
[self GetLatest];
}
else if ([btn.currentTitle isEqualToString:GJText(@"历史轨迹")])
{
TrackViewController *vc = [TrackViewController new];
[self.navigationController pushViewController:vc animated:YES];
}
else if ([btn.currentTitle isEqualToString:GJText(@"电子围栏")])
{
ElectronicFenceViewController *vc = [ElectronicFenceViewController new];
[self.navigationController pushViewController:vc animated:YES];
}
else if ([btn.currentTitle isEqualToString:GJText(@"定位说明")])
{
MarkExplainViewController *vc = [MarkExplainViewController new];
[self.navigationController pushViewController:vc animated:YES];
}
}];
[button setImage:ImageName_(image) forState:0];
button.frame = CGRectMake(SCREEN_WIDTH-Adapted(40)-15, self.topView.bottom+Adapted(30)+Adapted(40)*i+15*i, Adapted(40), Adapted(40));
button.backgroundColor = KKWhiteColorColor;
[UICommon setBtnUpImageDownTitle:button];
button.layer.cornerRadius = 5;
button.layer.masksToBounds = YES;
button.tag = i;
[self.view addSubview:button];
}
}
- (GDMapView *)gdMapView
{
if (!_gdMapView)
{
_gdMapView = [[GDMapView alloc] initWithFrame:CGRectMake(0, self.topView.bottom, SCREEN_WIDTH, SCREEN_HEIGHT-self.topView.bottom)];
}
return _gdMapView;
}
- (GoogleMapView *)googleMapView
{
if (!_googleMapView)
{
_googleMapView = [[GoogleMapView alloc] initWithFrame:CGRectMake(0, self.topView.bottom, SCREEN_WIDTH, SCREEN_HEIGHT-self.topView.bottom)];
}
return _googleMapView;
}
- (UIView *)topView
{
if (!_topView)
{
_topView = [UICommon ui_view:CGRectZero backgroundColor:KKWhiteColorColor cornerRadius:0 borderWidth:0 borderColor:KKWhiteColorColor];
_topView.frame = CGRectMake(0, iPhoneX_NavHeight, SCREEN_WIDTH, Adapted(70));
/// 定位图片
UIImageView *mapImg = [UICommon ui_imageView:CGRectZero fileName:@"icon_home_base_station"];
self.mapImg = mapImg;
[_topView addSubview:mapImg];
[mapImg mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_topView).offset(10);
make.centerY.equalTo(_topView);
make.size.mas_equalTo(CGSizeMake(30, 30));
}];
/// 定位时间Label
UILabel *timeLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontADA_(11) textColor:KKTextBlackColor text:@"" Radius:3];
self.timeLabel = timeLabel;
[_topView addSubview:timeLabel];
[timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(mapImg.mas_right).inset(15);
make.top.equalTo(_topView).offset(15);
}];
/// 电量Label
UILabel *electricityLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentLeft font:FontADA_(11) textColor:KKGrey102 text:@"" Radius:0];
self.electricityLabel = electricityLabel;
[_topView addSubview:electricityLabel];
[electricityLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(_topView.mas_right).inset(10);
make.centerY.equalTo(timeLabel);
}];
/// 电池图片
UIImage *imgs = ImageName_(@"icon_home_electricity_100");
UIImageView *electricityImg = [UICommon ui_imageView:CGRectZero fileName:@""];
self.electricityImg = electricityImg;
[_topView addSubview:electricityImg];
[electricityImg mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(electricityLabel.mas_left).inset(2);
make.centerY.equalTo(electricityLabel);
make.size.mas_equalTo(imgs.size);
}];
/// 位置
UILabel *addLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentLeft font:FontADA_(12) textColor:KKTextBlackColor text:GJText(@"当前位置未知,请确保设备开机且能够联网,再点击定位按钮进行定位") Radius:0];
self.addLabel = addLabel;
[_topView addSubview:addLabel];
[addLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(timeLabel.mas_left);
make.right.equalTo(_topView.mas_right).inset(15);
make.centerY.equalTo(_topView.mas_centerY);
}];
}
return _topView;
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
LatestLocationModel *model = APIManager.sharedManager.laloModel;
[self UpdataMapViewLocation:model];
}
#pragma mark 主动请求位置下发
/// 主动请求位置下发
- (void)GetLatest
{
NSString *imei = APIManager.sharedManager.deviceModel.imei;
[UICommon MessageUpload:@"定位中"];
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
[[[APIManager sharedManager] APGET:F(@"%@/%@", Latest_location_app_instructions_URL,imei) parameters:parameters resultClass:nil] subscribeNext:^(id _Nullable x) {
NSLog(@"-->%@",x);
} error:^(NSError * _Nullable error) {
NSDictionary *dic = error.userInfo;
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]];
}];
}
#pragma mark 获取设备最新位置信息(推送时使用)
/// 获取设备最新位置信息(推送时使用)
- (void)UpdataLatestlocation:(NSString *)imei
{
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
[[[APIManager sharedManager] APGET:F(@"%@/%@", Latest_location_app_URL,imei) parameters:parameters resultClass:LatestLocationModel.class] subscribeNext:^(LatestLocationModel *model) {
[UICommon HidenLoading];
if (model != nil)
{
[self UpdataMapViewLocation:model];
}
NSLog(@"-->%@",model);
} error:^(NSError * _Nullable error) {
NSDictionary *dic = error.userInfo;
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]];
}];
}
- (void)UpdataMapViewLocation:(LatestLocationModel *)model
{
if(model)
{
self.gdMapView.laloModel = model;
self.timeLabel.text = model.updateTime;
self.addLabel.text = model.addr;
self.electricityLabel.text = F(@"%ld%%", model.battery);
self.electricityImg.image = [UICommon GetElectricityImg:model.battery];
/// 定位类型 LBS GPS,WIFI
if ([model.locationType isEqualToString:@"LBS"])
self.mapImg.image = ImageName_(@"icon_home_base_station");
else if ([model.locationType isEqualToString:@"GPS"])
self.mapImg.image = ImageName_(@"icon_histroy_g");
else if ([model.locationType isEqualToString:@"WIFI"])
self.mapImg.image = ImageName_(@"icon_home_wifi");
[self.mapImg mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.topView).offset(10);
make.centerY.equalTo(self.topView);
make.size.mas_equalTo(CGSizeMake(AdaptedHeight(self.mapImg.image.size.width), AdaptedHeight(self.mapImg.image.size.height)));
}];
[self.addLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.timeLabel.mas_left);
make.right.equalTo(self.topView.mas_right).inset(15);
make.top.equalTo(self.topView.mas_centerY);
}];
}
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end