天气预报地图左魔兽世界右下角小地图怎么有小地图

我的天气预报和google地图无法定位,如何解决
- 智能手机游戏之家
我的天气预报和google地图无法定位,如何解决
今天刚刚入手legend,发现天气预报和google地图都无法定位我的位置了,开了gprs定位,没有开gps,以前用g3这样是可以定位的,请问高手如何解决?
不区分大小写匿名
如何开启GPRS,没找到,也不知道如何定位,请指教
我小白,我问下,这个天气用GPRS可以定位不?
相关知识等待您来回答
该问题来自:iPhone,android等智能手机的信息分享平台,提供免费的智能手机游戏下载手机领域专家
当前分类官方群讨论、解答、交流电脑数码相关的疑难问题
& &SOGOU - 京ICP证050897号全国天气预报地图_2014全国天气预报地图
- noYes游戏王国
单机游戏分类
与“全国天气预报地图”相关应用推荐
中央天气预报是一个与系统内置的天气预报功能类似的程序, 但这是专门针对中国市场定制......
中央天气预报是一个与系统内置的天气预报功能类似的程序, 但这是专门针对中国市场定制的天气程序,功能更加详细、丰富。V2.3版,为你带来清爽体验:1.中央天气预报ipad版正式推出!2.修复了某些城市日期出现错误的情况。3.对界面进行了细微的调整。4.程序优化,Bug修复,带来更清爽的体验。本程序支持各地当前天气的实况显示。提供最近一周的气温,将天气趋势准确把握。中央天气预报的不同之处在于,这是为中国订做的程序,数据量更多,从省,市,到全国各区县。(如广东佛山市,你可以选到顺德,三水,南海)同时天气信息也很详尽, 支持PM2.5,风力风向,湿度,紫外线,穿衣指数等。
eWeather拥有简单时尚的操作界面,准确的天气信息以及大量的数据资料,为您提供了10日之......
eWeather拥有简单时尚的操作界面,准确的天气信息以及大量的数据资料,为您提供了10日之内的天气预报和气压表(气压表包含了24小时的气压信息),以及地震信息等等。eWeather可以预报世界范围内超过13万个城市的天气状况,这些数据均由欧洲的和美国的独家提供!)特点o 可以大范围覆盖欧洲,亚洲和美国地区o 24小时之内每小时一次预报更新o 可以预报长达10日之内的天气预报o 即时天气信息o 气压表o 24小时的气压和温度趋势o 地震信息o 全球海洋表面温度o 专为iphone5和ipad设计的个性用户界面o 来自 和可信赖的天气资源o 10日内的详细天气预报包含超过15种气象参数o 天文数据日出日落以及月出月落o 每小时的天气预报拥有5种以上不同的参数o 世界时钟 eWeather HD is a visually stunning, feature-rich weather app for your iPhone, iPad or iPod touch. Get accurate weather conditions and ten-day forecasts, severe weather alerts and maps, temperature on your home screen, multi-layered weather maps and more! Download the power of eWeather HD to your iPhone or iPad! eWeather HD will help you to plan your outdoor activities with the amazing accuracy. Just take a look at the Weather Clock and you’ll be informed when you should take an umbrella! eWeather HD also includes interactive weather maps, earthquake map and detailed severe weather maps. eWeather HD uses two sources (located in the U.S. and E.U.) to bring you precise hourly forecasts as well as a full ten day forecast. Multi-provider system lets you choose the most accurate weather data for your location. eWeather HD uses latest technology to show you the current temperature (or feels like temperature) of any location right on your iPhone/iPad/iPod touch Home Screen! In addition to the temperature badge, you can set up the app to notify you of any changes in the weather as they happen, right in the Lockscreen and Notification Center. BaROMeter - a diagram showing the pressure changes during the past 24 hours. Now you always know the cause of headaches or migraines if it is linked with changes in the air pressure. When a dangerous pressure change has been detected the diagram will change the color. Another great feature is a weather alert system which includes push notifications and notification center support. This makes it even easier to keep tabs on what’s going on around you. Enjoy the weather! Key Features o Two Reliable, Accurate Data Sources based in the U.S. and E.U o Long-term ten-day weather forecast o Precise 24-hourly forecasts o Two color schemes (Black and White) o Severe weather areas on the map (interactive, vector-based) o “Follow me” (weather based on your physical location) o Severe weather advisories, watches and warnings (U.S. and E.U.) o Weather maps as they appear on TV (multilayered severe weather, current weather, weather forecast and earthquakes) o Realtime informing about weather (Notification Center, PUSH) o Current temperature / “Feels like” temperature on your home screen using the “app badges” o World Time
World Weather
World earthquakes
World Sea surface temperatures (map overview detailed display) * Ad-free. No limitations. No subscription fees. No hidden costs. Frequent updates. Features include o 130,000 locations worldwide o Unique clock-like interface o Current weather conditions including humidity, wind and pressure o Sunrise and Sunset times o Moon day, Moon phase, Moon set and Moon rise times o Feels like temperature o Hourly precipitation forecasts o Rainfall amounts ( only) o Barometric pressure and the temperature trend diagram displays the last 24 hours o Hourly UV forecast o Alternative way of displaying negative temperatures on home screen o Locations can be added by GPS, Zip Code, or by browsing the location list o Space Weather Predictions Geomagnetic activity forecast (NOAA) Specifications o Available in 37 languages (translated by native speakers) o Full retina display support (HD graphics)
【网易应用携手北纬通信】独家特约限免,详情请关注网易应用!网易应用
,爱正......
【网易应用携手北纬通信】独家特约限免,详情请关注网易应用!网易应用
,爱正版也爱免费,每天带来最给力限免应用推荐。实时实景天气、温度、湿度、风向、生活指数、灾害预警让您足不出户便可知道全国各地实况天气。提供全国各区、县、市、省等2500多个城市的天气情况,是支持中国城市最多的iOS天气预报软件之一。全国省会城市实景图片拍摄。您可以在我的城市界面查询并添加城市,方便您随时随地获取最新天气资讯。1、支持全国2500多个地区天气预报,覆盖几乎所有的县级城市;2、支持未来7天天气预报;3、实景图片展示全国35个旅游城市的天气实景;4、生活指数空气污染、穿衣、紫外线、洗车 、逛街、旅游等生活指数; 5、全国灾害预警天气提示; 6、支持汽车尾号限行、日出日落;7、支持黄历查询;功能1、支持自动定位当前的城市;2、城市搜索功能、城市添加或者删除;3、微博、Facebook、Twitter等天气信息分享;4、支持摄氏度与华氏度自由切换;5、支持不同背景切换;
o 本软件实时从中国权威的气象数据源取回未来七天的天气预报信息与当前天气实况信息......
o 本软件实时从中国权威的气象数据源取回未来七天的天气预报信息与当前天气实况信息。o 一屏显示全部七天的天气信息与当前天气,一目了然,不用多次点击。o 更新天气数据时需要联上互联网。o 您下载或购买的是此软件工具本身,不包含天气数据。? ? ?
天气类应用分类推荐
? ? ?上次更新内容- 优化启动流程,加快了启动速度。- 当无网络连接时,显示上一次缓存的天气数据 (蓝色背景)。
苏州天气预报V1.0- 天气数据来自网络,支持查询苏州市及周边城市的天气情况;- 默认显示......
苏州天气预报V1.0- 天气数据来自网络,支持查询苏州市及周边城市的天气情况;- 默认显示当日的气象数据,还能预报未来3天的天气;- 气象数据包含天气状况、温度、湿度、风向、风力等;- 使用方便快捷,非常实用
Weather HD是ipad上知名度非常高的一款天气软件,售价为0.99美元。它似乎是为iPad炫机而......
Weather HD是ipad上知名度非常高的一款天气软件,售价为0.99美元。它似乎是为iPad炫机而生,曾有人把它和元素周期表那款软件相提并论,认为是iPad必备软件之一。他的画面确实非常华丽,华丽得让专业气象台都自愧不如,相比起画面的动画,展示天气数据的方式就简单多了,最多支持显示未来4天的气象情况,Weather HD可以设置显示温度为摄氏温度。 优点超炫的天气软件,iPad必备,一款天气预报软件作出了这样的效果,让气象台情何以堪。华丽无比的Weather HD,炫机必备之物。缺点天气预报功能不是很强大.还误报.
“全国天气预报地图”相关资讯推荐
更新时间:&&&&点击次数:0次
更新时间:&&&&点击次数:0次
更新时间:&&&&点击次数:0次
更新时间:&&&&点击次数:0次
更新时间:&&&&点击次数:0次
手游资讯推荐
Copyright & 2004- noYes游戏王国 版权所有&
公司:建始县鼎盛广告
备案号:沪ICP备号-4IOS_地图_定位_天气预报_Block回调_单例
H:/1021/00_block回调.h/*
通过block回调
定义block代码块,目的是解析完成之后调用
返回值是 void
参数是 数组,里面的每个成员是一个NSString*/
typedef void(^WeatherFinishedBlock)(NSArray *dataList);
@interface WeatherXMLPaser : NSObject
// 解析器解析数据,参数1是要解析的数据,参数2是解析完毕回调的代码块
- (void)parserWeatherData:(NSData *)data
completion:(WeatherFinishedBlock)
//--------------------------------------------------------
@interface WeatherXMLPaser()
// 成员记住block代码块
WeatherFinishedBlock
_FinishedB
//---------------------------------------------------------
#pragma mark - 成员方法
#pragma mark 解析器解析数据,参数1是要解析的数据,参数2是完毕时调用的代码块
- (void)parserWeatherData:(NSData *)data
completion:(WeatherFinishedBlock)completion
// 0. 记录块代码
_FinishedBlock =
// 1. 实例化XML解析器
NSXMLParser *parser = [[NSXMLParser alloc]initWithData:data];
// 2. 设置代理为 当前的WeatherXMLPaser
[parser setDelegate:self];
// 3. 解析器开始解析
[parser parse];
//--------------------------------------------------------
#pragma mark - XML解析代理方法,结束解析文档
- (void)parserDidEndDocument:(NSXMLParser *)parser
// 解析结束,调用代码块,参数是,解析完的成员NSString数组
// 通过block代码块回调,通知调用方解析结果
_FinishedBlock(_dataList);
//--------------------------------------------------------
// 1) 实例化单例 天气XML解析器
WeatherXMLPaser *parser = [WeatherXMLPaser sharedWeatherXMLPaser];
// 2)解析器解析数据,参数1是要解析的数据,参数2是解析完毕要执行的代码块
// 并且将解析完的数组 作为参数传递进来
[parser parserWeatherData:data completion:^(NSArray *dataList) {
// 解析完成了,打印输出
Weather *w = [Weather weatherWithArray:dataList];
H:/1021/00_Singleton单例.m/*
1,静态实例变量
2,类方法,allocWithZone
3,类方法,sharedXXX
// 单例第1步:静态实例变量
static WeatherXMLPaser *sharedI
// 单例第2步:类方法,allocWithZone
+ (id)allocWithZone:(struct _NSZone *)zone
static dispatch_once_t onceT
dispatch_once(&onceToken, ^{
sharedInstance = [super allocWithZone:zone];
return sharedI
// 单例第3步:类方法,shared方法
+ (WeatherXMLPaser *)sharedWeatherXMLPaser
static dispatch_once_t onceT
dispatch_once(&onceToken, ^{
// alloc方法会自动调用allocWithZone方法
sharedInstance = [[WeatherXMLPaser alloc]init];
return sharedI
H:/1021/01_地图_MainViewController.m//
MainViewController.m
Created by apple on 13-10-21.
Copyright (c) 2013年 itcast. All rights reserved.
@interface MainViewController : UIViewController
#import "MainViewController.h"
//#import "MyAnnotation.h"
#import "MyAnnotation2.h"
@interface MainViewController ()
MKMapView *_mapV
@implementation MainViewController
1. 地图跟踪模式
MKUserTrackingMode None = 0
不跟踪用户位置
MKUserTrackingMode Follow
跟踪用户位置
MKUserTrackingMode FollowWithHeading
带方向跟踪用户位置(汽车车头方向)
2. 地图模式
MKMapType Standard = 0,
标准地图(最省电的模式)
MKMapType Satellite,
MKMapType Hybrid
混合地图(最费电)
3. 设置地图显示区域,距离以米为单位(iOS7升级的,不再自动调整地图现实比例)
MKCoordinateRegion MKCoordinateRegionMakeWithDistance
4. 添加大头针
addAnnotation:(id )annotation
凡是遵守MKAnnotation协议的对象都可以成为大头针
5. 自定义大头针,地图视图是支持大头针视图重用的!
如果在mapView:(MKMapView *)mapView viewForAnnotation:
(id)annotation
方法中,返回nil,地图视图会使用默认的方法绘制大头针
如果重写了mapView:viewForAnnotation方法,在程序中,调用
addAnnotation:annotation方法时,
annotation会以参数的形式传递给自定义大头针视图的方法
提示:如果是自定义大头针视图,需要设置canShowCallout属性,
才能够和视图进行交互
6. 如果重写了mapView:viewForAnnotation方法
跟踪用户信息时,同样会调用该方法!
如果既要跟踪用户信息,同时又要显示大头针
(譬如:显示汽车位置,同时显示加油站的大头针)
如果传入的annotation不是自定义大头针视图,直接返回nil,
使用地图默认的方法绘制大头针
如果是自定义视图,则设置大头针属性
#pragma mark - 实例化视图
- (void)loadView
// 设置全屏
self.view = [[UIView alloc]initWithFrame:[UIScreen mainScreen].applicationFrame];
// 1. 实例化地图视图
MKMapView *mapView = [[MKMapView alloc]initWithFrame:self.view.bounds];
[self.view addSubview:mapView];
// 设置MapView的代理为当前控制器
[mapView setDelegate:self];
// 2. 设置跟踪用户位置的模式
[mapView setUserTrackingMode:MKUserTrackingModeFollow animated:YES];
// 3. 设置地图的类型
[mapView setMapType:MKMapTypeHybrid];
_mapView = mapV
- (void)viewDidLoad
[super viewDidLoad];
// 根据经纬度,生成Coordinate2D坐标
CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(+30., +116.);
// 默认大头针,通过Coordinate2D生成大头针 annotation
MyAnnotation *annotation = [[MyAnnotation alloc]initWithCoordinate:coord title:@"我的地盘" subtitle:nil];
// 自定义大头针,可以通过setter方法生成大头针 annotation2
MyAnnotation2 *annotation = [[MyAnnotation2 alloc]init];
[annotation setCoordinate:coord];
[annotation setTitle:@"我的地盘"];
[annotation setIcon:@"head0.png"];
NSLog(@"%p %@", annotation, annotation);
// 添加大头针到mapView
[_mapView addAnnotation:annotation];
// 自定义大头针,可以通过setter方法生成大头针 annotation2
MyAnnotation2 *annotation2 = [[MyAnnotation2 alloc]init];
// 根据经纬度,生成Coordinate2D坐标
CLLocationCoordinate2D coord2 = CLLocationCoordinate2DMake(+50., +116.);
[annotation2 setCoordinate:coord2];
[annotation2 setTitle:@"MJ"];
[annotation2 setIcon:@"head0.png"];
// 添加大头针到mapView
[_mapView addAnnotation:annotation2];
// 根据Coordinate2D坐标的经纬度,生成Location对象
CLLocation *location1 = [[CLLocation alloc]initWithLatitude:coord.latitude longitude:coord.longitude];
// 根据Coordinate2D坐标的经纬度,生成Location对象
CLLocation *location2 = [[CLLocation alloc]initWithLatitude:coord2.latitude longitude:coord2.longitude];
// 计算两个Location对象之间的距离
CLLocationDistance distance = [location1 distanceFromLocation:location2];
NSLog(@"两点间距离 %f", distance);
#pragma mark - 地图代理方法
#pragma mark 每次用户位置变化都会被调用,意味着非常费电
- (void)mapView:(MKMapView *)mapView
didUpdateUserLocation:(MKUserLocation *)userLocation
NSLog(@"%@ %@", userLocation.location, userLocation.title);
// 利用location中的经纬度设置地图显示的坐标区域CoordinateRegion
// 参数2,和参数3的意思是:X,Y半径
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(
userLocation.location.coordinate, 100.0, 100.0);
// 设置地图的显示区域,以用户所在位置为中心点,半径为100米
[mapView setRegion:region animated:YES];
#pragma mark - 自定义大头针视图,参数中的annotation就是添加到mapView的大头针
- (MKAnnotationView *)mapView:(MKMapView *)mapView
viewForAnnotation:(id)annotation
// 如果传入的annotation不是自定义大头针视图,直接返回nil,
// 即使用地图默认的方法绘制大头针
// 如果是自定义视图,才要设置大头针属性,牢记~~~~
if (![annotation isKindOfClass:[MyAnnotation2 class]]) {
// 同cell,标准优化代码
static NSString *ID = @"ID";
MKAnnotationView *view = [mapView
dequeueReusableAnnotationViewWithIdentifier:ID];
// 如果没有找到可重用的大头针视图,才实例化新的
if (view == nil) {
view = [[MKAnnotationView alloc]initWithAnnotation:annotation
reuseIdentifier:ID];
// 点击大头针,可以突显出来
view.canShowCallout = YES;
// 设置大头针视图独一无二的属性
// 1) 如果大头针视图是从缓冲池取出的,必须要重新设置大头针
[view setAnnotation:annotation];
// 2) 设置大头针图像,需手动转成MyAnnotation2 *,才能使用子类的特有属性
[view setImage:[UIImage imageNamed:((MyAnnotation2 *)annotation).icon]];
H:/1021/01_地图_MyAnnotation.m//
MyAnnotation.m
Created by apple on 13-10-21.
Copyright (c) 2013年 itcast. All rights reserved.
// 大头针,遵守协议
@interface MyAnnotation : NSObject
// 提示,因为要给对象属性赋值,所以此处实例化对象方法不能用工厂方法,
原因就是类方法中,无法访问对象的成员变量
// 坐标,标题,子标题
- (id)initWithCoordinate:(CLLocationCoordinate2D)coordinate
title:(NSString *)title subtitle:(NSString *)
#import "MyAnnotation.h"
@interface MyAnnotation()
CLLocationCoordinate2D
@property (strong, nonatomic) NSString *strong_str1;
@property (copy, nonatomic) NSString *copy_str2;
@implementation MyAnnotation
copy常用于NSString,目的是改变新的不影响旧的
copy出来的对象是不可变对象,
而mutableCopy出来的是可变对象
因此,只有对不可变对象进行copy的时候,相当于retain
属性是非arc的,但是在arc中同样可以使用,表示对象是可以复制的
使用copy描述符,在给对象赋值时,会建立对象的副本
在非arc开发中,字符串类型NSString通常使用copy描述符
copy属性通常被称为深复制
strong 属于arc的,在非arc中不可以使用,等同于非arc中的retain
使用strong描述符,在给对象赋值时,会建立对象的指针副本
strong属性通常被称为浅复制
在性能上strong会略微比copy要好,建议大家在日常开发中使用strong。
- (id)initWithCoordinate:(CLLocationCoordinate2D)coordinate
title:(NSString *)title subtitle:(NSString *)subtitle
if (self = [super init]) {
// 为成员赋值
_coordinate =
_subtitle =
NSMutableString *string = [NSMutableString string];
[string setString:@"oldValue"];
// strong 浅拷贝,只是建立指针副本
self.strong_str1 =
// copy 深拷贝,建立对象副本
self.copy_str2 =
// 因此,string和strong_str1两个指针指向的是同一个地址
// 而copy_str2指向的是一个新的地址(新复制的对象的地址)
NSLog(@"%p %p %p", string, self.strong_str1, self.copy_str2);
[string setString:@"newValue"];
// string和strong_str1指向同一个,故结果是newValue
// copy_str2指向的是一个新开的地址,故结果依然是oldValue
NSLog(@"%@ %@ %@", string, self.strong_str1, self.copy_str2);
#pragma mark - 只读属性,即只有getter方法
- (CLLocationCoordinate2D)coordinate
- (NSString *)title
- (NSString *)subtitle
H:/1021/01_地图_MyAnnotation2.h//
MyAnnotation2.h
Created by apple on 13-10-21.
Copyright (c) 2013年 itcast. All rights reserved.
// 自定义大头针,遵守协议
@interface MyAnnotation2 : NSObject
// 坐标,标题,副标题
@property (nonatomic, assign) CLLocationCoordinate2D
@property (nonatomic, copy) NSString *
@property (nonatomic, copy) NSString *
// 大头针图标的名字
@property (nonatomic, strong) NSString *
H:/1021/02_定位_MainViewController.m//
MainViewController.m
Created by apple on 13-10-21.
Copyright (c) 2013年 itcast. All rights reserved.
#import "MainViewController.h"
@interface MainViewController ()
// 成员:LocationManager定位管理器
CLLocationManager
*_locationM
// 成员:Geocoder 地理位置编码器
CLGeocoder
@implementation MainViewController
1. 要使用定位服务,都是从CLLocationManager开始的
2. 在实际应用开发中,需要判断用户的定位服务是否打开,
如果没有打开,需要提示用户
直接用定位管理器的类方法locationServicesEnabled可以判断。
3. 在大多数情况下CLLocation的精度不如MKMapView高,但是因为不使用UIMapView,
相对性能较好!
4. 使用CLLocation时,最好设置定位精度,以省电
kCLLocationAccuracy B
// 最佳精度(最耗电)
kCLLocationAccuracy NearestTenM
// 最近10米范围内定位
kCLLocationAccuracy HundredM
kCLLocationAccuracy K
kCLLocationAccuracy ThreeK
使用startUpdatingLocation可以开始定位用户位置
如果不需要持续跟踪用户的行踪,定位之后,
最好stopUpdatingLocation替用户省电!
5. 根据经纬度计算地名
- (void)reverseGeocodeLocation:(CLLocation *)location
completionHandler:(CLGeocodeCompletionHandler)completionH
6. 根据地名计算经纬度
- (void)geocodeAddressString:(NSString *)addressString
completionHandler:(CLGeocodeCompletionHandler)completionH
- (void)viewDidLoad
[super viewDidLoad];
// 1. 判断定位服务是否可用
if ([CLLocationManager locationServicesEnabled]) {
// 1) 实例化定位管理器
_locationManager = [[CLLocationManager alloc]init];
// 2) 设置定位管理器的代理,当位置变化时,会调用代理的方法
[_locationManager setDelegate:self];
// 3) 设置定位管理器的精度
[_locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
// 4) 开启用户定位功能
[_locationManager startUpdatingLocation];
// 5) 实例化geocoder
_geocoder = [[CLGeocoder alloc]init];
// 根据地名,反向解析出坐标
[_geocoder geocodeAddressString:@"西湖"
completionHandler:^(NSArray *placemarks, NSError *error) {
// placemarks 地点、地标
CLPlacemark *placemark = placemarks[0];
NSLog(@"%@ %@", placemark.location, placemark.country);
NSLog(@"没有开启定位服务");
#pragma mark - 定位管理器代理方法
#pragma mark 更新位置,只要用户的位置发生变化,就会被调用,非常费电!
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations
// 数组locations中只有一个位置
NSLog(@"%@", locations[0]);
// 根据地名,反向解析出坐标
[_geocoder reverseGeocodeLocation:locations[0]
completionHandler:^(NSArray *placemarks, NSError *error) {
// placemarks 地点、地标
CLPlacemark *placemark = placemarks[0];
// 中国北京市昌平区回龙观地区建材城西路67号
NSLog(@"%@", placemark);
H:/1021/03_天气预报_MainViewController.m//
MainViewController.m
03.天气预报
Created by apple on 13-10-21.
Copyright (c) 2013年 itcast. All rights reserved.
#import "MainViewController.h"
#import "WeatherXMLPaser.h"
#import "Weather.h"
#import "WeatherAnnonation.h"
天气预报项目流程
1,POST请求抓起网络数据
2,XML解析response的数据
4,XML返回的地址信息,利用Geocoder地理编码器获得经纬度,设置大头针位置
5,XML中的图片名作大头针annotation的自定义image
6,大头针的title显示城市名和温度和空气质量PM2.5 PM10
7,大头针的subtitle显示天气详情
@interface MainViewController ()
// 操作队列
NSOperationQueue
// 地图视图
// 地理编码器
CLGeocoder
@implementation MainViewController
在开发网络应用时,通常服务器考虑到负载的问题,会禁止同一个地址,
连续多次提交请求
大多数这种情况下,服务器只响应一次!
解决办法:隔一秒抓一次!
1) 抓取城市天气信息的数据,不能够并发执行,要开个新线程,即在background运行
需要依次执行=>NSURLConntection需要发送同步请求
2) 如果单纯使用同步请求,会阻塞主线程,影响用户体验
3) 新开一个线程,在后台依次抓取所有城市的数据
#pragma mark - 实例化视图
- (void)loadView
self.view = [[UIView alloc]initWithFrame:[UIScreen mainScreen].applicationFrame];
_mapView = [[MKMapView alloc]initWithFrame:self.view.bounds];
// 1. 如果需要旋转屏幕,同时自动调整视图大小
[_mapView setAutoresizingMask:UIViewAutoresizingFlexibleHeight |
UIViewAutoresizingFlexibleWidth];
// 2. 添加到根视图
[self.view addSubview:_mapView];
// 3. 设置mapView的代理 为当前控制器
[_mapView setDelegate:self];
#pragma mark - 加载数据
- (void)viewDidLoad
[super viewDidLoad];
_queue = [[NSOperationQueue alloc]init];
_geocoder = [[CLGeocoder alloc]init];
// 在后台线程加载城市数据
[self performSelectorInBackground:@selector(loadWeatherData)
withObject:nil];
#pragma mark 自定义方法,加载城市天气数据,后台运行
- (void)loadWeatherData
NSLog(@"%@", [NSThread currentThread]);
[self loadWeatherDataWithCityName:@"北京"];
[NSThread sleepForTimeInterval:1.0f];
[self loadWeatherDataWithCityName:@"重庆"];
[NSThread sleepForTimeInterval:1.0f];
[self loadWeatherDataWithCityName:@"上海"];
#pragma mark 自定义方法,POST请求,抓取网络天气数据
- (void)loadWeatherDataWithCityName:(NSString *)cityName
// 1. NSURL
NSString *urlString = @".cn/WebServices/WeatherWebService.asmx/getWeatherbyCityName";
NSURL *url = [NSURL URLWithString:urlString];
// 2. NSMutableURLRequest,POST请求
NSMutableURLRequest *request = [NSMutableURLRequest
requestWithURL:url
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:2.0f];
// 1) 指定数据体
NSString *bodyString = [NSString stringWithFormat:@"theCityName=%@",
cityName];
// 中文必须转码 NSUTF8StringEncoding
NSData *bodyData = [bodyString dataUsingEncoding:NSUTF8StringEncoding];
// 设置请求体
[request setHTTPBody:bodyData];
// 2) 指定http请求方式
[request setHTTPMethod:@"POST"];
// 3. NSURLConnection,同步请求,response用于接收返回的内容
NSURLResponse *response =
NSData *data = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response error:nil];
// 1) 实例化单例 天气XML解析器
WeatherXMLPaser *parser = [WeatherXMLPaser sharedWeatherXMLPaser];
// 2) 解析
[parser parserWeatherData:data completion:^(NSArray *dataList) {
// 解析完成的回调方法中,填充Model
Weather *w = [Weather weatherWithArray:dataList];
// 根据城市名称,使用地理编码器获取到对应的经纬度,然后设置大头针的位置
[_geocoder geocodeAddressString:w.cityName
completionHandler:^(NSArray *placemarks, NSError *error) {
// 地标有个location成员,location里面有2D坐标
CLPlacemark *placemark = placemarks[0];
// 大头针安插在此
WeatherAnnonation *annonation = [[WeatherAnnonation alloc]init];
// 指定大头针的经纬度位置
annonation.coordinate = placemark.location.
annonation.title = [NSString stringWithFormat:@"%@ %@", w.cityName, w.temperature];
annonation.subtitle = [NSString stringWithFormat:@"%@ %@", w.todayInfo, w.wind];
annonation.imageName = w.imageN
[_mapView addAnnotation:annonation];
#pragma mark - 地图视图代理方法,viewForAnnotation
- (MKAnnotationView *)mapView:(MKMapView *)mapView
viewForAnnotation:(id)annotation
// 要判断isKindOfClass,如果不是自定义的,就用默认的,即return nil
// 如果传入的annotation不是自定义大头针视图,直接返回nil,
// 即使用地图默认的方法绘制大头针
// 如果是自定义视图,才要设置大头针属性,牢记~~~~
if (![annotation isKindOfClass:[WeatherAnnonation class]]) {
static NSString *ID = @"ID";
MKAnnotationView *view = [mapView
dequeueReusableAnnotationViewWithIdentifier:ID];
if (view == nil) {
view = [[MKAnnotationView alloc]initWithAnnotation:annotation
reuseIdentifier:ID];
// 设置大头针,可以被点击后呼出
view.canShowCallout = YES;
// 设置大头针视图独一无二的属性
// 1) 如果大头针视图是从缓冲池取出的,必须要重新设置大头针
view.annotation =
// 设置图像
// 2) 设置大头针图像,需手动转成WeatherAnnonation *,才能使用子类的特有属性
[view setImage:[UIImage imageNamed:((WeatherAnnonation *)annotation).icon]];
H:/1021/03_天气预报_Weather.m//
03.天气预报
Created by apple on 13-10-21.
03.天气预报
@interface Weather : NSObject
#pragma mark 工厂方法
+ (Weather *)weatherWithArray:(NSArray *)
// 1. 城市名
@property (strong, nonatomic) NSString *cityN
// 2. 今天的信息
@property (strong, nonatomic) NSString *todayI
// 3. 风向
@property (strong, nonatomic) NSString *
// 4. 图片名
@property (strong, nonatomic) NSString *imageN
// 5. 气温
@property (strong, nonatomic) NSString *
#import "Weather.h"
@implementation Weather
+ (Weather *)weatherWithArray:(NSArray *)array
Weather *w = [[Weather alloc]init];
w.cityName = array[1];
w.todayInfo = array[6];
w.wind = array[7];
w.imageName = array[8];
w.temperature = array[5];
// 重写toString方法
- (NSString *)description
return [NSString stringWithFormat:
self, self.cityName, self.todayInfo,
self.wind, self.imageName, self.temperature];
H:/1021/03_天气预报_WeatherAnnonation.h//
WeatherAnnonation.h
03.天气预报
Created by apple on 13-10-21.
Copyright (c) 2013年 itcast. All rights reserved.
@interface WeatherAnnonation : NSObject
// 覆盖协议里面的成员,坐标,标题,副标题,图片名
@property (nonatomic, assign) CLLocationCoordinate2D
@property (nonatomic, copy) NSString *
@property (nonatomic, copy) NSString *
@property (strong, nonatomic) NSString *imageN
H:/1021/03_天气预报_WeatherXMLPaser.h//
WeatherXMLPaser.h
03.天气预报
Created by apple on 13-10-21.
定义block代码块,目的是解析完成之后调用
返回值是 void
参数是 数组,里面的每个成员是一个NSString
typedef void(^WeatherFinishedBlock)(NSArray *dataList);
@interface WeatherXMLPaser : NSObject
// 单例,返回解析器对象
+ (WeatherXMLPaser *)sharedWeatherXMLP
// 解析器解析数据,参数1是要解析的数据,参数2是解析完毕回调的代码块
- (void)parserWeatherData:(NSData *)data
completion:(WeatherFinishedBlock)
H:/1021/03_天气预报_WeatherXMLPaser.m//
WeatherXMLPaser.m
03.天气预报
Created by apple on 13-10-21.
天气预报项目流程
1,POST请求抓起网络数据
2,XML解析response的数据
4,XML返回的地址信息,利用Geocoder地理编码器获得经纬度,设置大头针位置
5,XML中的图片名作大头针annotation的自定义image
6,大头针的title显示城市名和温度和空气质量PM2.5 PM10
7,大头针的subtitle显示天气详情
#import "WeatherXMLPaser.h"
// 单例第1步:静态实例变量
static WeatherXMLPaser *sharedI
// 要想解析XML 必须遵守协议
@interface WeatherXMLPaser()
// 自定义block代码块
WeatherFinishedBlock
_FinishedB
// 解析结果的字符串数组,根节点是,其余节点名全是
NSMutableArray
// 临时文本字符串
NSMutableString
@implementation WeatherXMLPaser
单例模板写法
1. 静态实例变量
static WeatherXMLPaser *sharedI
2. allocWithZone
3. shared方法*/
#pragma mark - 单例方法
// 单例第2步:类方法,allocWithZone
+ (id)allocWithZone:(struct _NSZone *)zone
static dispatch_once_t onceT
dispatch_once(&onceToken, ^{
sharedInstance = [super allocWithZone:zone];
return sharedI
// 单例,返回解析器对象
// 单例第3步:类方法,shared方法
+ (WeatherXMLPaser *)sharedWeatherXMLPaser
static dispatch_once_t onceT
dispatch_once(&onceToken, ^{
sharedInstance = [[WeatherXMLPaser alloc]init];
return sharedI
#pragma mark - 成员方法
#pragma mark 解析器解析数据,参数1是要解析的数据,参数2是完毕时调用的代码块
- (void)parserWeatherData:(NSData *)data
completion:(WeatherFinishedBlock)completion
// 0. 记录块代码
_FinishedBlock =
// 1. 实例化XML解析器
NSXMLParser *parser = [[NSXMLParser alloc]initWithData:data];
// 2. 设置代理为 当前的WeatherXMLPaser
[parser setDelegate:self];
// 3. 解析器开始解析
[parser parse];
#pragma mark - XML解析代理方法
#pragma mark 5. 结束解析文档
- (void)parserDidEndDocument:(NSXMLParser *)parser
// 解析结束,调用代码块,参数是,解析完的NSString数组
// 通过block代码块回调,通知调用方解析结果
_FinishedBlock(_dataList);
#pragma mark 2. 开始解析元素节点
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
attributes:(NSDictionary *)attributeDict
// 根节点是,其余节点名全是
// 如果节点名是ArrayOfString,说明是根节点,准备好数组_dataList,装数据
if ([elementName isEqualToString:@"ArrayOfString"]) {
if (_dataList) {
[_dataList removeAllObjects];
// 无论是什么节点开始了,都要将临时文本清空,用于拼装文本节点
[_tempStr setString:@""];
#pragma mark 4. 结束解析节点,重点
- (void)parser:(NSXMLParser *)parser
didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
// 根节点是,其余节点名全是
NSString *result = [NSString stringWithString:_tempStr];
// 如果结束的节点是,就把拼装好的文本节点,添加到数组_dataList
if ([elementName isEqualToString:@"string"]) {
[_dataList addObject:result];
#pragma mark 1. 开始解析文档,初始化准备工作
- (void)parserDidStartDocument:(NSXMLParser *)parser
// 懒加载临时文本字符串
if (_tempStr == nil) {
_tempStr = [NSMutableString string];
// 懒加载结果数组
if (_dataList == nil) {
_dataList = [NSMutableArray array];
#pragma mark 6. 解析出错
- (void)parser:(NSXMLParser *)parser
parseErrorOccurred:(NSError *)parseError
NSLog(@"解析出错 %@", parseError.localizedDescription);
// 置空临时文本
[_tempStr setString:@""];
#pragma mark 3. 发现文本内容(一个文本节点可能会解析多次)
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
// 追加文本
[_tempStr appendString:string];
您对本文章有什么意见或着疑问吗?请到您的关注和建议是我们前行的参考和动力&&
您的浏览器不支持嵌入式框架,或者当前配置为不显示嵌入式框架。

我要回帖

更多关于 360浏览器左下角广告 的文章

 

随机推荐