城市地图

城市地图

#import "AppDelegate.h"#import "ViewController.h"@interface AppDelegate ()@end@implementation AppDelegate// 只有当应用在前台时,该方法才会被调用- (void)application:(UIApplication *)application
didReceiveLocalNotification:(UILocalNotification*)notification{    // 如果应用程序在前台,将应用程序图标上红色徽标中数字设为0
    application.applicationIconBadgeNumber = 0;    // 使用UIAlertView显示本地通知的信息
    [[[UIAlertView alloc] initWithTitle:@"收到通知"message:notification.alertBody delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil] show];
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{    // 应用程序再次进入前台时,将应用程序徽标设置0
    application.applicationIconBadgeNumber = 0;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    // Override point for customization after application launch.
    ViewController *vc = [[ViewController alloc]init];    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc];    self.window.rootViewController = nav;    return YES;
}#import "ViewController.h"#import "TwoViewController.h"@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>{    UITableView *table;    NSDictionary *dic;    NSString *province;    NSString *city;    
    //通知
    UIApplication *app;
}@end@implementation ViewController- (void)viewDidLoad {
    [super viewDidLoad];    
    //初始化app
    app = [UIApplication sharedApplication];    
    //标题
    self.navigationItem.title = @"城市列表";    //初始化表格
    table = [[UITableView alloc]initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStyleGrouped];
    table.delegate = self;
    table.dataSource = self;
    [self.view addSubview:table];    
    //初始化字典
   
    dic = @{@"河北省":@[@"石家庄",@"邯郸",@"燕郊"],@"陕西省":@[@"西安",@"渭南",@"咸阳"],@"山西省":@[@"运城",@"太原",@"临汾"]};    
    UIBarButtonItem *tongzhi = [[UIBarButtonItem alloc]initWithTitle:@"通知" style:UIBarButtonItemStylePlain target:self action:@selector(tongzhis)];    self.navigationItem.leftBarButtonItem = tongzhi;    UIBarButtonItem *quxiao = [[UIBarButtonItem alloc]initWithTitle:@"取消通知" style:UIBarButtonItemStylePlain target:self action:@selector(quxiaos)];    self.navigationItem.rightBarButtonItem = quxiao;
    
}//通知-(void)tongzhis
{    
    if([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)])
    {
        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
    }    
    // 创建一个本地通知
    UILocalNotification *notification = [[UILocalNotification alloc]init];    // 设置通知的触发时间
    notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:3];;    // 设置通知的时区
    notification.timeZone = [NSTimeZone defaultTimeZone];    // 设置通知的重复发送的事件间隔
    notification.repeatInterval = kCFCalendarUnitHour;    // 设置通知的声音
    notification.soundName = @"gu.mp3";    // 设置当设备处于锁屏状态时,显示通知的警告框下方的title
    notification.alertAction = @"打开";    // 设置通知是否可显示Action
    notification.hasAction = YES;    // 设置通过通知加载应用时显示的图片
    notification.alertLaunchImage = @"logo.png";    // 设置通知内容
    notification.alertBody = @"亲,好几天不登陆,Tom猫想念你了!";    // 设置显示在应用程序上红色徽标中的数字
    notification.applicationIconBadgeNumber = 1;    // 设置userinfo,用于携带额外的附加信息。
    NSDictionary *info = @{@"fkjava.org": @"key"};
    notification.userInfo = info;    // 调度通知
    [app scheduleLocalNotification:notification];  // ①}//取消通知-(void)quxiaos
{    // 获取所有处于调度中本地通知数组
    NSArray *localArray = [app scheduledLocalNotifications];    if (localArray)
    {        for (UILocalNotification *noti in localArray)
        {            NSDictionary *dict = noti.userInfo;            if (dict)
            {                // 如果找到要取消的通知
                NSString *inKey = [dict objectForKey:@"key"];                if ([inKey isEqualToString:@"fkjava.org"])
                {                    // 取消调度该通知
                    [app cancelLocalNotification:noti];  // ②
                }
            }
        }
    }
}//设置行数- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{    NSString *key = [dic.allKeys objectAtIndex:section];    return [[dic objectForKey:key]count];
}//设置内容- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{    static NSString*str = @"sdf";    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: str];    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str];
    }    NSString *key = [dic.allKeys objectAtIndex:indexPath.section];
    cell.textLabel.text = [[dic objectForKey:key]objectAtIndex:indexPath.row];    return cell;
}//设置分区数- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{    return dic.count;
}//设置分区标题-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{    return [dic.allKeys objectAtIndex:section];
}//跳转-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    TwoViewController *second = [[TwoViewController alloc]init];    NSString *key = [dic.allKeys objectAtIndex:indexPath.section];
    second.city  = [[dic objectForKey:key]objectAtIndex:indexPath.row];
    
    [self.navigationController pushViewController:second animated:YES];
}@end#import <UIKit/UIKit.h>#import <MapKit/MapKit.h>@interface TwoViewController : UIViewController@property (nonatomic,strong)NSString *city;@end#import "TwoViewController.h"#import <MapKit/MapKit.h>@interface TwoViewController()<MKMapViewDelegate>@property (nonatomic,strong)MKMapView *mapView;//地图视图@end@implementation TwoViewController-(MKMapView *)mapView
{    if (!_mapView) {
        _mapView = [[MKMapView alloc] initWithFrame:self.view.frame];
        _mapView.delegate = self;
        _mapView.zoomEnabled = YES;
        _mapView.scrollEnabled = YES;
        _mapView.pitchEnabled = YES;
        _mapView.rotateEnabled = YES;
        _mapView.mapType = MKMapTypeStandard;//综合地图
        _mapView.showsUserLocation = YES;
    }    return _mapView;
}
- (void)viewDidLoad {
    [super viewDidLoad];    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.mapView];    
    UIBarButtonItem *bar1 = [[UIBarButtonItem alloc] initWithTitle:@"省会位置" style:UIBarButtonItemStylePlain target:self action:@selector(locateProvince)];    UIBarButtonItem *bar2 = [[UIBarButtonItem alloc] initWithTitle:@"当前位置" style:UIBarButtonItemStylePlain target:self action:@selector(locateCurrentLocation:)];    self.navigationItem.rightBarButtonItems = @[bar1,bar2];
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];    self.navigationItem.title = self.city;
}

-(void)getmap:(NSString *)name{
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder geocodeAddressString:name completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
        CLPlacemark *place = [placemarks lastObject];
        CLLocation *loc = place.location;        dispatch_async(dispatch_get_main_queue(), ^{
            [self.mapView setRegion:MKCoordinateRegionMake(loc.coordinate, MKCoordinateSpanMake(0.1, 0.1)) animated:YES];
            
            MKCircle *circle = [MKCircle circleWithCenterCoordinate:loc.coordinate radius:100];            
            //添加图像覆盖层
            [self.mapView addOverlay:circle];
        });
        
    }];
}
-(MKOverlayPathRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(nonnull id<MKOverlay>)overlay
{
    MKCircle *circle = (MKCircle *)overlay;
    MKCircleRenderer *circleView = [[MKCircleRenderer alloc] initWithCircle:circle];
    circleView.fillColor = [UIColor cyanColor];
    circleView.strokeColor = [UIColor redColor];
    circleView.alpha = 0.3;    return circleView;
}
-(void)locateProvince
{
    [self getmap:self.city];
}
-(void)locateCurrentLocation:(id)sender
{
    [self getmap:@"北京市海淀区上地七街软件园南站"];
}@end


转载于:https://my.oschina.net/zhouwenhuan/blog/637338

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ECharts是一个非常强大的数据可视化库,它提供了各种类型的图表,包括城市地图。使用ECharts绘制城市地图可以展示各个城市的数据分布情况,比如人口分布、经济发展水平等。 要使用ECharts绘制城市地图,首先需要准备好地图数据。ECharts提供了各种地图数据文件,包括中国的省级行政区划、世界各国的地图等。可以根据自己的需求选择相应的地图数据文件。 接下来,需要引入ECharts库和相关的地图数据文件到项目中。然后创建一个div容器,用来展示地图。在JavaScript代码中,通过ECharts提供的API来配置地图的样式、数据等属性。最后调用ECharts的渲染方法将地图展示在页面上。 以下是一个简单的示例代码,展示如何使用ECharts绘制中国地图: ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>ECharts 城市地图示例</title> <script src="https://cdn.jsdelivr.net/npm/echarts@5.2.0/dist/echarts.min.js"></script> </head> <body> <div id="chart" style="width: 800px; height: 600px;"></div> <script> // 初始化echarts实例 var myChart = echarts.init(document.getElementById('chart')); // 引入地图数据 echarts.registerMap('china', chinaMapData); // 配置地图样式和数据 var option = { title: { text: '中国城市地图示例', left: 'center' }, tooltip: { trigger: 'item' }, series: [{ type: 'map', map: 'china' }] }; // 使用刚指定的配置项和数据显示图表 myChart.setOption(option); </script> </body> </html> ``` 上述代码中,需要将`chinaMapData`替换成你所使用的地图数据文件路径或数据对象。在示例中,我们创建了一个id为`chart`的div容器,然后使用ECharts的API初始化echarts实例,并引入中国地图数据。最后,配置地图的样式和数据,最终将图表渲染在页面上。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值