123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663 |
- //
- // JXGoogleMapVC.m
- // shiku_im
- //
- // Created by 1 on 2018/8/20.
- // Copyright © 2018年 Reese. All rights reserved.
- //
- #import "JXGoogleMapVC.h"
- #import <GoogleMaps/GoogleMaps.h>
- #import <GoogleMaps/GoogleMaps.h>
- #import <CoreLocation/CoreLocation.h>
- #import "JXNearMarkCell.h"
- #import "JXMapData.h"
- #import "SPAlertController.h"
- @interface JXGoogleMapVC () <GMSMapViewDelegate,UIScrollViewDelegate,CLLocationManagerDelegate,UITableViewDelegate,UITableViewDataSource,JXActionSheetVCDelegate>
- @property (nonatomic, strong) GMSMapView *gooMapView;
- @property (nonatomic, strong) CLLocationManager *locationManager;
- @property (nonatomic, strong) GMSMarker *marker;
- @property (nonatomic, strong) GMSGeocoder *geocoder;
- @property (nonatomic, strong) GMSMutableCameraPosition *camera;
- @property (nonatomic, strong) NSMutableArray *nearMarkArray;
- @property (nonatomic, strong) JXPlaceMarkModel *model;
- @property (nonatomic, assign) CGRect frame;
- @property (nonatomic, strong) JXNearMarkCell *lastCell;
- @end
- @implementation JXGoogleMapVC
- - (instancetype)init {
- if (self = [super init]) {
- self.title = Localized(@"JXUserInfoVC_Loation");
- self.heightHeader = _locationType ==JXGooLocationTypeShowStaticLocation ? 0 : JX_SCREEN_TOP;
- self.heightFooter = 0;
- self.isGotoBack = YES;
- [self createHeadAndFoot];
- _nearMarkArray = [[NSMutableArray alloc] init];
- if (_locationType ==JXGooLocationTypeShowStaticLocation) {
- UIButton *backBtn = [[UIButton alloc] initWithFrame:CGRectMake(15, JX_SCREEN_TOP - 38, 31, 31)];
- [backBtn setBackgroundImage:[UIImage imageNamed:@"map_back"] forState:UIControlStateNormal];
- [backBtn addTarget:self action:@selector(actionQuit) forControlEvents:UIControlEventTouchUpInside];
- [self.view addSubview:backBtn];
- // UIButton* btn = [UIFactory createButtonWithImage:@"title_more" highlight:nil target:self selector:@selector(moreBtnAction)];
- // btn.frame = CGRectMake(JX_SCREEN_WIDTH-24-8, JX_SCREEN_TOP - 34, 24, 24);
- // [self.tableHeader addSubview:btn];
- UIView *baseView = [[UIView alloc] initWithFrame:CGRectMake(0, JX_SCREEN_HEIGHT-100, JX_SCREEN_WIDTH, 100)];
- baseView.backgroundColor = [UIColor whiteColor];
- [self.view addSubview:baseView];
-
- UILabel *adrLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 40, JX_SCREEN_WIDTH-20*3-60, 20)];
- adrLabel.text = self.placeNames;
- [baseView addSubview:adrLabel];
-
- UIButton* btn = [UIFactory createButtonWithImage:@"adress_navigation" highlight:nil target:self selector:@selector(moreBtnAction)];
- btn.frame = CGRectMake(CGRectGetMaxX(adrLabel.frame)+20, 20, 60, 60);
- [baseView addSubview:btn];
-
- //复位
- UIButton * resetLoca = [[UIButton alloc]initWithFrame:CGRectMake(JX_SCREEN_WIDTH -80+30-15, JX_SCREEN_HEIGHT -100-50, 30, 30)];
- [resetLoca setImage:[UIImage imageNamed:@"ic_greeting_checked"] forState:UIControlStateNormal];
- [resetLoca addTarget:self action:@selector(resetMapCenter) forControlEvents:UIControlEventTouchUpInside];
- [self.view addSubview:resetLoca];
- } else {
- //发送
- if(self.isSend){
- _sendButton = [UIFactory createCommonButton:Localized(@"JX_Send") target:self action:@selector(onSelect)];
- _sendButton.frame = CGRectMake(JX_SCREEN_WIDTH-60, JX_SCREEN_TOP - 34, 60, 24);
- [_sendButton setBackgroundImage:nil forState:UIControlStateNormal];
- [_sendButton setBackgroundImage:nil forState:UIControlStateHighlighted];
- [_sendButton setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
- [self.tableHeader addSubview:_sendButton];
- }
- }
- if (!_locations)
- _locations = [[NSMutableArray alloc]init];
- }
- return self;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self createGoogleMap];
- [self customView];
- [self startLocation];
- self.tableBody.contentSize = CGSizeMake(0, JX_SCREEN_HEIGHT - JX_SCREEN_TOP);
- }
- -(void)startLocation{
- if (_locationType == JXGooLocationTypeShowStaticLocation) {
- JXMapData * staticData = [_locations firstObject];
- self.latitude = [staticData.latitude doubleValue];
- self.longitude = [staticData.longitude doubleValue];
- // [self makeMapCenter:staticData];
- // [self addPointAnnotations:_locations];
- self.title = staticData.title;
-
- GMSMarker *marker = [[GMSMarker alloc] init];
- marker.position = CLLocationCoordinate2DMake(self.latitude, self.longitude);
- marker.title = self.title;
- // marker.snippet = @"Hong Kong";
- marker.icon = [UIImage imageNamed:@"position"];
- marker.map = _gooMapView;
- [self resetMapCenter]; // 移动镜头
- }else {
- //定位服务
- _locationManager=[[CLLocationManager alloc]init];
- if ([CLLocationManager authorizationStatus]==kCLAuthorizationStatusNotDetermined){
- [_locationManager requestWhenInUseAuthorization];
- }else if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusAuthorizedWhenInUse){
- _locationManager.delegate=self;
- _locationManager.desiredAccuracy=kCLLocationAccuracyBest;
- [_locationManager startUpdatingLocation];
- }
- }
- }
- - (void)actionSheet:(JXActionSheetVC *)actionSheet didButtonWithIndex:(NSInteger)index {
- if (index == 0) {
- [self onDaoHangForIOSMap];
- }
- }
- -(void)moreBtnAction{
-
- JXActionSheetVC *actionVC = [[JXActionSheetVC alloc] initWithImages:nil names:@[Localized(@"JX_MapApple")]];
- actionVC.delegate = self;
- [g_navigation.subViews.lastObject presentViewController:actionVC animated:NO completion:nil];
-
- // SPAlertController *alertSheet = [SPAlertController alertControllerWithTitle:nil message:nil preferredStyle:SPAlertControllerStyleActionSheet animationType:SPAlertAnimationTypeDefault];
- //
- // // UIAlertController * alertSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
- //// SPAlertAction *actionApple = [SPAlertAction actionWithTitle:Localized(@"JX_MapApple") style:SPAlertActionStyleDefault handler:^(SPAlertAction * _Nonnull action) {
- //// NSLog(@"苹果");
- //// [self onDaoHangForIOSMap];
- //// }];
- //// [alertSheet addAction:actionApple];
- //
- // if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"iosamap://"]]){
- // SPAlertAction * actionAMap = [SPAlertAction actionWithTitle:Localized(@"JX_MapGaode") style:SPAlertActionStyleDefault handler:^(SPAlertAction * _Nonnull action) {
- // NSLog(@"高德");
- // [self onDaoHangForGaoDeMap];
- // }];
- // [alertSheet addAction:actionAMap];
- // }
- // if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"baidumap://"]]) {
- // SPAlertAction * actionBaidu = [SPAlertAction actionWithTitle:Localized(@"JX_MapBaidu") style:SPAlertActionStyleDefault handler:^(SPAlertAction * _Nonnull action) {
- // NSLog(@"百度");
- // [self onDaoHangForBaiDuMap];
- // }];
- // [alertSheet addAction:actionBaidu];
- // }
- //
- // if ( [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"comgooglemaps://"]]){
- // SPAlertAction *actionGoogle = [SPAlertAction actionWithTitle:Localized(@"JX_MapGoogle") style:SPAlertActionStyleDefault handler:^(SPAlertAction *action) {
- // NSLog(@"谷歌");
- // [self onGoogleMap];
- // }];
- // [alertSheet addAction:actionGoogle];
- // }
- //
- // // if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"qqmap://"]]) {
- // // UIAlertAction *actionQq = [UIAlertAction actionWithTitle:@"腾讯地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
- // // NSLog(@"腾讯地图");
- // // [self onQQMap];
- // // }];
- // // [alertSheet addAction:actionQq];
- // // }
- //
- // SPAlertAction * cancelAction = [SPAlertAction actionWithTitle:Localized(@"JX_Cencal") style:SPAlertActionStyleCancel handler:^(SPAlertAction * _Nonnull action) {
- // NSLog(@"取消");
- // }];
- // [alertSheet addAction:cancelAction];
- //
- //
- // // if ([alertSheet respondsToSelector:@selector(popoverPresentationController)]) {
- // // alertSheet.popoverPresentationController.sourceView = self.view; //必须加
- // // alertSheet.popoverPresentationController.sourceRect = CGRectMake(0, JX_SCREEN_HEIGHT, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT);//可选,我这里加这句代码是为了调整到合适的位置
- // // }
- // [self presentViewController:alertSheet animated:YES completion:nil];
-
-
- }
- #pragma mark ------------------------------ 导航 - iosMap
- -(void) onDaoHangForIOSMap
- {
- //起点
- // CLLocation * location = [[CLLocation alloc]initWithLatitude:latitude longitude:longitude];
- // location = [location locationMarsFromBaidu];
- //
- // CLLocationCoordinate2D coor =location.coordinate;
- // MKMapItem *currentLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:coor addressDictionary:nil]];
- // currentLocation.name =@"我的位置";
-
- JXMapData * staticData = [_locations firstObject];
- CLLocationCoordinate2D toCoor = [staticData coordinate2D];
- // self.title = staticData.title;
- //目的地的位置
- CLLocation * location2 = [[CLLocation alloc]initWithLatitude:toCoor.latitude longitude:toCoor.longitude];
- // location2 = [location2 locationMarsFromBaidu];
-
- CLLocationCoordinate2D coor2 =location2.coordinate;
- // CLLocationCoordinate2D coords = self.location;
-
-
- MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:coor2 addressDictionary:nil]];
-
- toLocation.name = staticData.title;
-
- NSArray *items = [NSArray arrayWithObjects:toLocation, nil];
- NSString * mode = MKLaunchOptionsDirectionsModeDriving;
- // switch (_seleIndex) {
- // case 1:
- // {
- // mode = MKLaunchOptionsDirectionsModeTransit;
- // }
- // break;
- // case 2:
- // {
- // mode = MKLaunchOptionsDirectionsModeDriving;
- // }
- // break;
- // case 3:
- // {
- // mode = MKLaunchOptionsDirectionsModeWalking;
- // }
- // break;
- //
- // default:
- // break;
- // }
- NSDictionary *options = @{ MKLaunchOptionsDirectionsModeKey:mode, MKLaunchOptionsMapTypeKey: [NSNumber numberWithInteger:MKMapTypeStandard], MKLaunchOptionsShowsTrafficKey:@YES };
- //打开苹果自身地图应用,并呈现特定的item
- [MKMapItem openMapsWithItems:items launchOptions:options];
- }
- #pragma mark ------------------------------ 导航 - 高德
- -(void) onDaoHangForGaoDeMap
- {
- // m 驾车:0:速度最快,1:费用最少,2:距离最短,3:不走高速,4:躲避拥堵,5:不走高速且避免收费,6:不走高速且躲避拥堵,7:躲避收费和拥堵,8:不走高速躲避收费和拥堵 公交:0:最快捷,2:最少换乘,3:最少步行,5:不乘地铁 ,7:只坐地铁 ,8:时间短 是
- // t = 0:驾车 =1:公交 =2:步行
-
- // NSString * t = @"0";
- // switch (_seleIndex) {
- // case 1:
- // {
- // t = @"1";
- // }
- // break;
- // case 2:
- // {
- // t = @"0";
- // }
- // break;
- // case 3:
- // {
- // t = @"2";
- // }
- // break;
- //
- // default:
- // break;
- // }
- //起点
- // CLLocation * location = [[CLLocation alloc]initWithLatitude:[SingleObject shareSingleObject].currentCoordinate.latitude longitude:[SingleObject shareSingleObject].currentCoordinate.longitude];
- // location = [location locationMarsFromBaidu];
- //
- // CLLocationCoordinate2D coor =location.coordinate;
-
- //目的地的位置
- // CLLocation * location2 = [[CLLocation alloc]initWithLatitude:self.location.latitude longitude:self.location.longitude];
- // location2 = [location2 locationMarsFromBaidu];
- //
- // CLLocationCoordinate2D coor2 =location2.coordinate;
- JXMapData * staticData = [_locations firstObject];
- CLLocationCoordinate2D toCoor = [staticData coordinate2D];
- // self.title = staticData.title;
- //目的地的位置
- CLLocation * location2 = [[CLLocation alloc]initWithLatitude:toCoor.latitude longitude:toCoor.longitude];
- // location2 = [location2 locationMarsFromBaidu];
-
- CLLocationCoordinate2D coor2 =location2.coordinate;
-
-
- // 导航 URL:iosamap://navi?sourceApplication=%@&poiname=%@&lat=%lf&lon=%lf&dev=0&style=0",@"ABC"
- // 路径规划 URL:iosamap://path?sourceApplication=applicationName&sid=BGVIS1&slat=39.92848272&slon=116.39560823&sname=A&did=BGVIS2&dlat=39.98848272&dlon=116.47560823&dname=B&dev=0&m=0&t=0
- // -- 不能直接让用户进入导航,应该给用户更多的选择,所以先进行路径规划
-
- // NSURL *myLocationScheme = [NSURL URLWithString:@"iosamap://path?sourceApplication=shikuim"];
-
-
-
-
- NSString *url = [[NSString stringWithFormat:@"iosamap://path?sourceApplication=shikuim&sid=BGVIS1&did=BGVIS2&dlat=%lf&dlon=%lf&dname=%@&dev=0",coor2.latitude,coor2.longitude,staticData.title] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
-
- if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:url]])// -- 使用 canOpenURL 判断需要在info.plist 的 LSApplicationQueriesSchemes 添加 iosamap
- {
- if ([[UIDevice currentDevice].systemVersion integerValue] >= 10) { //iOS10以后,使用新API
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url] options:@{} completionHandler:^(BOOL success) {
- NSLog(@"scheme调用结束"); }];
- }else { //iOS10以前,使用旧API
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
- }
- }else{
- [g_App showAlert:Localized(@"JX_MapSelNotInstall")];
- }
-
-
- }
- #pragma mark ------------------------------ 导航 - 百度
- -(void) onDaoHangForBaiDuMap
- {
- // 百度地图如何调起APP进行导航
- // mode 导航模式,固定为transit、driving、walking,分别表示公交、驾车和步行
- NSString * modeBaiDu = @"driving";
- // switch (_seleIndex) {
- // case 1:
- // {
- // modeBaiDu = @"transit";
- // }
- // break;
- // case 2:
- // {
- // modeBaiDu = @"driving";
- // }
- // break;
- // case 3:
- // {
- // modeBaiDu = @"walking";
- // }
- // break;
- //
- // default:
- // break;
- // }
-
- JXMapData * staticData = [_locations firstObject];
- CLLocationCoordinate2D toCoor = [staticData coordinate2D];
- // self.title = staticData.title;
- //目的地的位置
- CLLocation * location2 = [[CLLocation alloc]initWithLatitude:toCoor.latitude longitude:toCoor.longitude];
- // location2 = [location2 locationMarsFromBaidu];
-
- CLLocationCoordinate2D coor2 =location2.coordinate;
-
- NSString *url = [[NSString stringWithFormat:@"baidumap://map/direction?origin=%lf,%lf&destination=%f,%f&mode=%@&src=公司|APP",coor2.latitude,coor2.longitude,coor2.latitude,coor2.longitude,modeBaiDu] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] ;
-
- // [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
-
- if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"baidumap://"]])// -- 使用 canOpenURL 判断需要在info.plist 的 LSApplicationQueriesSchemes 添加 baidumap 。
- {
- if ([[UIDevice currentDevice].systemVersion integerValue] >= 10) { //iOS10以后,使用新API
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url] options:@{} completionHandler:^(BOOL success) {
- NSLog(@"scheme调用结束");
- }];
- }else { //iOS10以前,使用旧API
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
- }
- }else{
- [g_App showAlert:Localized(@"JX_MapSelNotInstall")];
- }
-
- }
- #pragma mark --- google
- -(void)onGoogleMap{
- JXMapData * staticData = [_locations firstObject];
- CLLocationCoordinate2D toCoor = [staticData coordinate2D];
- // self.title = staticData.title;
- //目的地的位置
- CLLocation * location2 = [[CLLocation alloc]initWithLatitude:toCoor.latitude longitude:toCoor.longitude];
- // location2 = [location2 locationMarsFromBaidu];
-
- CLLocationCoordinate2D coor2 =location2.coordinate;
-
- NSString *url = [[NSString stringWithFormat:@"comgooglemaps://?x-source=%@&saddr=&daddr=%f,%f&directionsmode=driving",@"shikuim",coor2.latitude, coor2.longitude] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
-
- if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"comgooglemaps://"]])// -- 使用 canOpenURL 判断需要在info.plist 的 LSApplicationQueriesSchemes 添加 baidumap 。
- {
- if ([[UIDevice currentDevice].systemVersion integerValue] >= 10) { //iOS10以后,使用新API
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url] options:@{} completionHandler:^(BOOL success) {
- NSLog(@"scheme调用结束"); }];
- }else { //iOS10以前,使用旧API
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
- }
- }else{
- [g_App showAlert:Localized(@"JX_MapSelNotInstall")];
- }
-
- }
- - (void)createGoogleMap {
- GMSCameraPosition *camera = nil;
- if (self.latitude == 0) {
- camera = [GMSCameraPosition cameraWithLatitude:22.290664
- longitude:114.195304
- zoom:14];
- }else{
- camera = [GMSCameraPosition cameraWithLatitude:self.latitude
- longitude:self.longitude
- zoom:14];
- }
-
- _gooMapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
- _gooMapView.delegate = self;
- self.view = _gooMapView;
-
- }
- - (void)locationManager:(CLLocationManager *)manager
- didUpdateLocations:(NSArray *)locations
- {
- CLLocation *curLocation = [locations lastObject];
- CLLocationCoordinate2D curCoordinate2D=curLocation.coordinate;
- [_locationManager stopUpdatingLocation];
- dispatch_async(dispatch_get_main_queue(), ^{
- // [_gooMapView clear];
- // _gooMapView.camera=[GMSCameraPosition cameraWithLatitude:curCoordinate2D.latitude longitude:curCoordinate2D.longitude zoom:14];
- self.longitude = curCoordinate2D.longitude;
- self.latitude = curCoordinate2D.latitude;
- });
- }
- -(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
- }
- -(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status{
- /**
- * 拿到授权发起定位请求
-
- */
- if (status == kCLAuthorizationStatusAuthorizedWhenInUse) {
- [_locationManager startUpdatingLocation];
- }
- }
- #pragma mark - 获取地理位置名称(地点名)
- - (void)mapView:(GMSMapView *)mapView didChangeCameraPosition:(GMSCameraPosition *)position{
-
- //反向地理编码
- [[GMSGeocoder geocoder]reverseGeocodeCoordinate:position.target completionHandler:^(GMSReverseGeocodeResponse * response, NSError * error) {
- if (response.results) {
- GMSAddress *address = response.results[0];
- NSLog(@"%@",address.thoroughfare);
- _address = address.thoroughfare;
- if (![_address isEqualToString:@""]) {
- JXPlaceMarkModel *place = [[JXPlaceMarkModel alloc] init];
- place.placeName = address.locality;
- place.address = _address;
- [_nearMarkArray removeAllObjects];
- [_nearMarkArray addObject:place];
- [_nearMarkTableView reloadData];
- }
- }
- }];
- }
- #pragma mark - 移动镜头 得到位置
- -(void)mapView:(GMSMapView *)mapView idleAtCameraPosition:(GMSCameraPosition *)position{
- if (_locationType == JXGooLocationTypeCurrentLocation) {
- self.longitude = position.target.longitude;
- self.latitude = position.target.latitude;
- }
-
- }
- - (nullable UIImage *)snapshotToImage:(CGSize)size {
- _gooMapView.myLocationEnabled = NO;
- CGPoint map_center = _gooMapView.center;
- UIGraphicsBeginImageContextWithOptions(size, NO, 0.0f);
- [_gooMapView drawViewHierarchyInRect:CGRectMake(0, -(map_center.y - size.height)-JX_SCREEN_TOP, _gooMapView.bounds.size.width, _gooMapView.bounds.size.height) afterScreenUpdates:YES];
- UIImage *snapshotImage = UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
-
- return snapshotImage;
- }
- - (void)getServerData {
-
- }
- - (void)customView{
- if (_locationType == JXGooLocationTypeShowStaticLocation) {
- //复位
- UIButton * resetLoca = [[UIButton alloc]initWithFrame:CGRectMake(JX_SCREEN_WIDTH -50, JX_SCREEN_HEIGHT -50, 30, 30)];
- [resetLoca setImage:[UIImage imageNamed:@"ic_greeting_checked"] forState:UIControlStateNormal];
- [resetLoca addTarget:self action:@selector(resetMapCenter) forControlEvents:UIControlEventTouchUpInside];
- [self.view addSubview:resetLoca];
-
- }else{
- //复位
- UIButton * resetLoca = [[UIButton alloc]initWithFrame:CGRectMake(JX_SCREEN_WIDTH -50, JX_SCREEN_HEIGHT -50, 30, 30)];
- [resetLoca setImage:[UIImage imageNamed:@"ic_greeting_checked"] forState:UIControlStateNormal];
- [resetLoca addTarget:self action:@selector(resetLocation) forControlEvents:UIControlEventTouchUpInside];
- [self.view addSubview:resetLoca];
- //当前位置图标
- UIImageView * pointImage = [[UIImageView alloc]initWithFrame:CGRectMake((JX_SCREEN_WIDTH - 30) /2, (JX_SCREEN_HEIGHT -64)/2 - 50 +10 +64, 30, 50)];
- pointImage.image = [UIImage imageNamed:@"position"];
- pointImage.userInteractionEnabled = NO;
- [self.view addSubview:pointImage];
- //周边地点列表
- _nearMarkTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, JX_SCREEN_HEIGHT - 100, JX_SCREEN_WIDTH, 100) style:UITableViewStylePlain];
- _nearMarkTableView.dataSource = self;
- _nearMarkTableView.delegate = self;
- _nearMarkTableView.separatorStyle = UITableViewCellSelectionStyleNone;
- [self.view addSubview:_nearMarkTableView];
- }
- }
- - (void)resetMapCenter {
- GMSCameraPosition *sydney = [GMSCameraPosition cameraWithLatitude:self.latitude
- longitude:self.longitude
- zoom:14];
- [_gooMapView setCamera:sydney];
-
- }
- - (void)onSelect {
- NSString *imagePath = [self screenShotAction];
-
- JXMapData * data = [[JXMapData alloc]init];
-
- if (_model != nil) {
- data.latitude = [NSString stringWithFormat:@"%f",_model.latitude];
- data.longitude = [NSString stringWithFormat:@"%f",_model.longitude];
- data.subtitle = _model.name;
- }else{
- data.latitude = [NSString stringWithFormat:@"%f",self.latitude];
- data.longitude = [NSString stringWithFormat:@"%f",self.longitude];
- data.subtitle = _address;
- }
-
- if (!data.subtitle || data.subtitle.length <= 0 || [data.subtitle isEqualToString:@"null"] || [data.subtitle isEqualToString:@"(null)"]) {
- if (g_server.address.length > 0) {
- data.subtitle = g_server.address;
- }else {
- data.subtitle = @"";
- }
- }
-
- data.imageUrl = imagePath;
-
- if(self.delegate != nil && [self.delegate respondsToSelector:self.didSelect])
- [self.delegate performSelectorOnMainThread:self.didSelect withObject:data waitUntilDone:NO];
-
- [self actionQuit];
-
- _delegate = nil;
- [_gooMapView removeFromSuperview];
- }
- -(NSString *)screenShotAction{
- UIImage *image = [self snapshotToImage:CGSizeMake(JX_SCREEN_WIDTH, JX_SCREEN_WIDTH/2.2)];
- UIImage *logoImage = [self addImageLogo:image text:[UIImage imageNamed:@"position"]];
- NSString* filePath = [FileInfo getUUIDFileName:@"jpg"];
- [g_server saveImageToFile:logoImage file:filePath isOriginal:NO];
- return filePath;
- }
- -(UIImage *)addImageLogo:(UIImage *)img text:(UIImage *)logo
- {
-
- int w = img.size.width;
- int h = img.size.height;
- // int logoWidth = 120;
- // int logoHeight = 200;
- CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
-
- CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);
- CGContextDrawImage(context, CGRectMake(0, 0, w, h), img.CGImage);
- // CGContextDrawImage(context, CGRectMake((w-logoWidth)/2, h/2-10, logoWidth, logoHeight), [logo CGImage]);
- CGImageRef imageMasked = CGBitmapContextCreateImage(context);
- CGContextRelease(context);
- CGColorSpaceRelease(colorSpace);
- return [UIImage imageWithCGImage:imageMasked];
- }
- - (void)resetLocation{
- [g_App showAlert:Localized(@"JXLoc_StartLocNotice")];
-
- }
- #pragma mark tableViewDelegate
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- if (_nearMarkArray.count>0) {
- return _nearMarkArray.count;
- }
- return 0;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- if (_nearMarkArray.count>0) {
- return _nearMarkArray.count*44;
- }
- return 0;
- }
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- JXNearMarkCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([JXNearMarkCell class])];
- if (cell == nil) {
- cell = [[JXNearMarkCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([JXNearMarkCell class])];
- }
- if (_nearMarkArray.count>0) {
- [cell refreshWithModel:[_nearMarkArray objectAtIndex:indexPath.row]];
- }
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- // [_locService stopUserLocationService];
- _selIndex = indexPath.row;
- JXPlaceMarkModel*model = [_nearMarkArray objectAtIndex:indexPath.row];
- model.longitude = self.longitude;
- model.latitude = self.latitude;
- model.name = self.address;
- self.model = model;
- JXNearMarkCell *cell = [tableView cellForRowAtIndexPath:indexPath];
- cell.selFlag.hidden = NO;
- if (self.lastCell != cell) {
- self.lastCell.selFlag.hidden = YES;
- }
- // self.textString = model.address;
- if (self.lastCell != cell) {
- self.lastCell = cell;
- }
- }
- @end
|