Skip to content

Commit

Permalink
美团地图优化
Browse files Browse the repository at this point in the history
  • Loading branch information
lookingstars committed Jul 16, 2015
1 parent d87f903 commit 21e0830
Show file tree
Hide file tree
Showing 16 changed files with 550 additions and 54 deletions.
120 changes: 80 additions & 40 deletions meituan.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Binary file not shown.
4 changes: 4 additions & 0 deletions meituan/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[UMSocialData setAppKey:UMAPPKEY];
[UMSocialWechatHandler setWXAppId:@"wx3b1ec5fee404cc3d" appSecret:@"e97199313f931035a765ee433e335dbb" url:@"http://www.fityun.cn/"];

//友盟初始化,对未安装QQ,微信的平台进行隐藏
// [UMSocialConfig hiddenNotInstallPlatforms:@[UMShareToQQ,UMShareToQzone,UMShareToWechatSession,UMShareToWechatTimeline]];
[UMSocialConfig hiddenNotInstallPlatforms:@[UMShareToWechatSession,UMShareToWechatTimeline]];




Expand Down
2 changes: 1 addition & 1 deletion meituan/Controller/Home/Shop/ShopViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ -(void)OnShareBtn:(UIButton *)sender{


// [UMSocialSnsService presentSnsIconSheetView:self appKey:UMAPPKEY shareText:@"测试高仿分享" shareImage:[UIImage imageNamed:@"bg_customReview_image_default"] shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToTencent,UMShareToRenren,UMShareToQzone, nil] delegate:self];
[UMSocialSnsService presentSnsIconSheetView:self appKey:UMAPPKEY shareText:@"在美国被禁的网站,请偷偷看" shareImage:[UIImage imageNamed:@"m1.jpg"] shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToTencent,UMShareToRenren,UMShareToQzone,UMShareToWechatTimeline,UMShareToWechatSession, nil] delegate:self];
[UMSocialSnsService presentSnsIconSheetView:self appKey:UMAPPKEY shareText:@"在美国被禁的网站,请偷偷看" shareImage:[UIImage imageNamed:@"m1.jpg"] shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToTencent,UMShareToRenren,UMShareToWechatTimeline,UMShareToWechatSession, nil] delegate:self];


//1.微信分享
Expand Down
131 changes: 118 additions & 13 deletions meituan/Controller/Map/JZMapViewControlle.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@
#import "JZMapViewControlle.h"
#import <MAMapKit/MAMapKit.h>
#import <AMapSearchKit/AMapSearchAPI.h>
#import "NetworkSingleton.h"
#import "CustomAnnotationView.h"

#import "JZMAAroundAnnotation.h"
#import "JZMAAroundModel.h"
#import "MJExtension.h"

#define kDefaultCalloutViewMargin -8
#define MAPKEY @"2812f1e8b5f3c1473e8928ae9130e63d"

@interface JZMapViewControlle ()<MAMapViewDelegate,AMapSearchDelegate>
Expand Down Expand Up @@ -49,6 +56,10 @@ - (void)viewDidLoad {
[self initControls];
[self initSearch];
[self initAttributes];//初始化数据

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[self getAroundMerchantData];
});
}

- (void)didReceiveMemoryWarning {
Expand Down Expand Up @@ -100,6 +111,64 @@ - (void)initAttributes
_pois = [NSMutableArray array];
}


//请求数据
//请求分类数据
-(void)getGroupData{
NSString *urlStr = @"http://api.meituan.com/group/v2/deal/cate-show-list?__skck=40aaaf01c2fc4801b9c059efcd7aa146&__skcy=ZcDSShW9Lc%2BTgbSrYF1Zt8hpdnc%3D&__skno=BD01BF5A-9B25-4152-898D-FC8D29B025A8&__skts=1436947023.082103&__skua=bd6b6e8eadfad15571a15c3b9ef9199a&__vhost=api.mobile.meituan.com&ci=1&cityId=1&client=iphone&movieBundleVersion=100&msid=48E2B810-805D-4821-9CDD-D5C9E01BC98A2015-07-15-15-51824&userid=104108621&utm_campaign=AgroupBgroupD100Fa20141120nanning__m1__leftflow___ab_pindaochangsha__a__leftflow___ab_gxtest__gd__leftflow___ab_gxhceshi__nostrategy__leftflow___ab_i550poi_ktv__d__j___ab_chunceshishuju__a__a___ab_gxh_82__nostrategy__leftflow___ab_i_group_5_3_poidetaildeallist__a__b___b1junglehomepagecatesort__b__leftflow___ab_gxhceshi0202__b__a___ab_pindaoquxincelue0630__b__b1___ab_i550poi_xxyl__b__leftflow___ab_i_group_5_6_searchkuang__a__leftflow___i_group_5_2_deallist_poitype__d__d___ab_pindaoshenyang__a__leftflow___ab_b_food_57_purepoilist_extinfo__a__a___ab_waimaiwending__a__a___ab_waimaizhanshi__b__b1___ab_i550poi_lr__d__leftflow___ab_i_group_5_5_onsite__b__b___ab_xinkeceshi__b__leftflowGhomepage_map&utm_content=4B8C0B46F5B0527D55EA292904FD7E12E48FB7BEA8DF50BFE7828AF7F20BB08D&utm_medium=iphone&utm_source=AppStore&utm_term=5.7&uuid=4B8C0B46F5B0527D55EA292904FD7E12E48FB7BEA8DF50BFE7828AF7F20BB08D&version_name=5.7";
}

//获取附近商家列表
-(void)getAroundMerchantData{
//取100组
NSString *urlStr = @"http://api.meituan.com/group/v1/deal/select/position/39.983478,116.318049/cate/1?__skck=40aaaf01c2fc4801b9c059efcd7aa146&__skcy=ji%2BV3hnRG9MHGaryLpiFV9Fiw5o%3D&__skno=1F082187-597D-4636-B088-B54186954C10&__skts=1436951992.642581&__skua=bd6b6e8eadfad15571a15c3b9ef9199a&__vhost=api.mobile.meituan.com&ci=1&client=iphone&distance=2051&fields=slug%2Ccate%2Csubcate%2Crdplocs%2Cimgurl%2Ctitle%2Csmstitle%2Cprice%2Cbrandname%2Cmname%2Crating%2Crate-count%2Capplelottery%2Cid&limit=30&movieBundleVersion=100&msid=48E2B810-805D-4821-9CDD-D5C9E01BC98A2015-07-15-15-51824&mypos=39.983478%2C116.318049&offset=0&sort=defaults&ste=_b0&userid=104108621&utm_campaign=AgroupBgroupD100Fa20141120nanning__m1__leftflow___ab_pindaochangsha__a__leftflow___ab_gxtest__gd__leftflow___ab_gxhceshi__nostrategy__leftflow___ab_i550poi_ktv__d__j___ab_chunceshishuju__a__a___ab_gxh_82__nostrategy__leftflow___ab_i_group_5_3_poidetaildeallist__a__b___b1junglehomepagecatesort__b__leftflow___ab_gxhceshi0202__b__a___ab_pindaoquxincelue0630__b__b1___ab_i550poi_xxyl__b__leftflow___ab_i_group_5_6_searchkuang__a__leftflow___i_group_5_2_deallist_poitype__d__d___ab_pindaoshenyang__a__leftflow___ab_b_food_57_purepoilist_extinfo__a__a___ab_waimaiwending__a__a___ab_waimaizhanshi__b__b1___ab_i550poi_lr__d__leftflow___ab_i_group_5_5_onsite__b__b___ab_xinkeceshi__b__leftflowGhomepage_map&utm_content=4B8C0B46F5B0527D55EA292904FD7E12E48FB7BEA8DF50BFE7828AF7F20BB08D&utm_medium=iphone&utm_source=AppStore&utm_term=5.7&uuid=4B8C0B46F5B0527D55EA292904FD7E12E48FB7BEA8DF50BFE7828AF7F20BB08D&version_name=5.7";

[[NetworkSingleton sharedManager] getAroundMerchantResult:nil url:urlStr successBlock:^(id responseBody){
NSLog(@"地图:获取附近商家成功");
NSMutableArray *dataArray = [responseBody objectForKey:@"data"];
if (dataArray.count>0) {

[_mapView removeAnnotations:_annotations];
[_annotations removeAllObjects];



for (int i = 0; i < dataArray.count; i++) {
JZMAAroundModel *jzmaaroundM = [JZMAAroundModel objectWithKeyValues:dataArray[i]];
//创建annotation

JZMAAroundAnnotation *annotation = [[JZMAAroundAnnotation alloc] init];

annotation.jzmaaroundM = jzmaaroundM;
annotation.title = jzmaaroundM.mname;
annotation.subtitle = [NSString stringWithFormat:@"%@",jzmaaroundM.price];
annotation.coordinate = CLLocationCoordinate2DMake(LATITUDE_DEFAULT, LONGITUDE_DEFAULT);
if (jzmaaroundM.rdplocs.count>0) {
NSDictionary *dic = jzmaaroundM.rdplocs[0];
NSNumber *lat = [dic objectForKey:@"lat"];
NSNumber *lng = [dic objectForKey:@"lng"];
annotation.coordinate = CLLocationCoordinate2DMake([lat doubleValue], [lng doubleValue]);
}
[_annotations addObject:annotation];
// [_mapView addAnnotation:annotation];

}
[self performSelectorOnMainThread:@selector(updateUI)withObject:_annotations waitUntilDone:YES];
}
} failureBlock:^(NSString *error){
NSLog(@"地图:获取附近商家失败:%@",error);
}];
}

-(void)updateUI{
NSLog(@"个数:%ld",_annotations.count);
for (int i = 0; i < _annotations.count; i++) {
[_mapView addAnnotation:_annotations[i]];
}
}



//相应事件
-(void)OnBackBtn:(UIButton *)sender{
[self.navigationController popViewControllerAnimated:YES];
Expand All @@ -112,6 +181,10 @@ -(void)locateAction{
[self searchAction];
}





//逆地理编码
//发起搜索请求
-(void)reGeoAction{
Expand Down Expand Up @@ -164,29 +237,49 @@ -(void)mapView:(MAMapView *)mapView didSelectAnnotationView:(MAAnnotationView *)
[self reGeoAction];
}

// CLLocationCoordinate2DMake(poi.location.latitude, poi.location.longitude)
// _mapView setCenterCoordinate:(CLLocationCoordinate2D) animated:
// _currentLocation = view.annotation

// 调整自定义callout的位置,使其可以完全显示
if ([view isKindOfClass:[CustomAnnotationView class]]) {
CustomAnnotationView *cusView = (CustomAnnotationView *)view;
CGRect frame = [cusView convertRect:cusView.calloutView.frame toView:_mapView];

frame = UIEdgeInsetsInsetRect(frame, UIEdgeInsetsMake(kDefaultCalloutViewMargin, kDefaultCalloutViewMargin, kDefaultCalloutViewMargin, kDefaultCalloutViewMargin));

if (!CGRectContainsRect(_mapView.frame, frame))
{
CGSize offset = [self offsetToContainRect:frame inRect:_mapView.frame];

CGPoint theCenter = _mapView.center;
theCenter = CGPointMake(theCenter.x - offset.width, theCenter.y - offset.height);

CLLocationCoordinate2D coordinate = [_mapView convertPoint:theCenter toCoordinateFromView:_mapView];

[_mapView setCenterCoordinate:coordinate animated:YES];
}

}

}

//显示地图标示view 大头针
-(MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id<MAAnnotation>)annotation{
if ([annotation isKindOfClass:[MAPointAnnotation class]])
{
static NSString *reuseIndetifier = @"annotationReuseIndetifier";
MAPinAnnotationView *annotationView = (MAPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseIndetifier];
CustomAnnotationView *annotationView = (CustomAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseIndetifier];
if (annotationView == nil)
{
annotationView = [[MAPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseIndetifier];
annotationView = [[CustomAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseIndetifier];
}
annotationView.canShowCallout = YES;
// annotationView.image = [UIImage imageNamed:@"icon_map_cateid_3"];


NSLog(@"+++++++");
if ([annotation isKindOfClass:[JZMAAroundAnnotation class]]){
annotationView.jzAnnotation = (JZMAAroundAnnotation *)annotation;
}
annotationView.canShowCallout = NO;
annotationView.image = [UIImage imageNamed:@"icon_map_cateid_1"];
// 设置中⼼心点偏移,使得标注底部中间点成为经纬度对应点
// annotationView.centerOffset = CGPointMake(0, -18);
return annotationView;
}

return nil;
}

Expand All @@ -212,7 +305,6 @@ -(void)onReGeocodeSearchDone:(AMapReGeocodeSearchRequest *)request response:(AMa
//地址搜索回调
-(void)onPlaceSearchDone:(AMapPlaceSearchRequest *)request response:(AMapPlaceSearchResponse *)response{
NSLog(@"地址搜索 requset:%@",request);
NSLog(@"地址搜索 response:%@",response);

//清空
[_mapView removeAnnotations:_annotations];
Expand All @@ -222,7 +314,6 @@ -(void)onPlaceSearchDone:(AMapPlaceSearchRequest *)request response:(AMapPlaceSe
//
if (response.pois.count > 0) {
_pois = [[NSMutableArray alloc] initWithArray:response.pois];
// _pois = response.pois;
for (int i = 0; i < _pois.count; i++) {
//标注
AMapPOI *poi = _pois[i];
Expand All @@ -240,6 +331,20 @@ -(void)onPlaceSearchDone:(AMapPlaceSearchRequest *)request response:(AMapPlaceSe





#pragma mark - Helpers

- (CGSize)offsetToContainRect:(CGRect)innerRect inRect:(CGRect)outerRect
{
CGFloat nudgeRight = fmaxf(0, CGRectGetMinX(outerRect) - (CGRectGetMinX(innerRect)));
CGFloat nudgeLeft = fminf(0, CGRectGetMaxX(outerRect) - (CGRectGetMaxX(innerRect)));
CGFloat nudgeTop = fmaxf(0, CGRectGetMinY(outerRect) - (CGRectGetMinY(innerRect)));
CGFloat nudgeBottom = fminf(0, CGRectGetMaxY(outerRect) - (CGRectGetMaxY(innerRect)));
return CGSizeMake(nudgeLeft ?: nudgeRight, nudgeTop ?: nudgeBottom);
}


/*
#pragma mark - Navigation
Expand Down
16 changes: 16 additions & 0 deletions meituan/Model/Map/JZMAAroundAnnotation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// JZMAAroundAnnotation.h
// meituan
//
// Created by jinzelu on 15/7/15.
// Copyright (c) 2015年 jinzelu. All rights reserved.
//

#import <MAMapKit/MAMapKit.h>
#import "JZMAAroundModel.h"

@interface JZMAAroundAnnotation : MAPointAnnotation

@property(nonatomic, strong) JZMAAroundModel *jzmaaroundM;

@end
13 changes: 13 additions & 0 deletions meituan/Model/Map/JZMAAroundAnnotation.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// JZMAAroundAnnotation.m
// meituan
//
// Created by jinzelu on 15/7/15.
// Copyright (c) 2015年 jinzelu. All rights reserved.
//

#import "JZMAAroundAnnotation.h"

@implementation JZMAAroundAnnotation

@end
19 changes: 19 additions & 0 deletions meituan/Model/Map/JZMAAroundModel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// JZMAAroundModel.h
// meituan
//
// Created by jinzelu on 15/7/15.
// Copyright (c) 2015年 jinzelu. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface JZMAAroundModel : NSObject

@property(nonatomic, strong) NSString *mname;//标题
@property(nonatomic, strong) NSNumber *price;//价格
@property(nonatomic, strong) NSString *imgurl;//图片

@property(nonatomic, strong) NSMutableArray *rdplocs;//坐标等

@end
13 changes: 13 additions & 0 deletions meituan/Model/Map/JZMAAroundModel.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// JZMAAroundModel.m
// meituan
//
// Created by jinzelu on 15/7/15.
// Copyright (c) 2015年 jinzelu. All rights reserved.
//

#import "JZMAAroundModel.h"

@implementation JZMAAroundModel

@end
7 changes: 7 additions & 0 deletions meituan/Others/Network/NetworkSingleton.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ typedef void(^FailureBlock)(NSString *error);



#pragma mark - 团购地图

#pragma mark - 获取附近商家列表
-(void)getAroundMerchantResult:(NSDictionary *)userInfo url:(NSString *)url successBlock:(SuccessBlock)successBlock failureBlock:(FailureBlock)failureBlock;






Expand Down
20 changes: 20 additions & 0 deletions meituan/Others/Network/NetworkSingleton.m
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,26 @@ -(void)getCateListResult:(NSDictionary *)userInfo url:(NSString *)url successBlo



#pragma mark - 团购地图

#pragma mark - 获取附近商家列表
-(void)getAroundMerchantResult:(NSDictionary *)userInfo url:(NSString *)url successBlock:(SuccessBlock)successBlock failureBlock:(FailureBlock)failureBlock{
AFHTTPRequestOperationManager *manager = [self baseHtppRequest];

//两种编码方式
// NSString *urlStr = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *urlStr = [url stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[manager GET:urlStr parameters:userInfo success:^(AFHTTPRequestOperation *operation, id responseObject){
successBlock(responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error){
NSString *errorStr = [error.userInfo objectForKey:@"NSLocalizedDescription"];
failureBlock(errorStr);
}];
}







Expand Down
File renamed without changes
22 changes: 22 additions & 0 deletions meituan/Views/Map/CustomAnnotationView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// CustomAnnotationView.h
// meituan
//
// Created by jinzelu on 15/7/15.
// Copyright (c) 2015年 jinzelu. All rights reserved.
//

#import <MAMapKit/MAMapKit.h>
#import "CustomCalloutView.h"
#import "JZMAAroundAnnotation.h"

@interface CustomAnnotationView : MAAnnotationView

@property(nonatomic, strong) CustomCalloutView *calloutView;

/*!
@brief 关联的annotation
*/
@property (nonatomic, strong) JZMAAroundAnnotation *jzAnnotation;

@end
Loading

0 comments on commit 21e0830

Please sign in to comment.