|
@@ -14,6 +14,8 @@
|
|
|
#import "AMMapAnnotaion.h"
|
|
#import "AMMapAnnotaion.h"
|
|
|
#import "AMAnnotationView.h"
|
|
#import "AMAnnotationView.h"
|
|
|
#import "AMMapView.h"
|
|
#import "AMMapView.h"
|
|
|
|
|
+#import "CLLocation+Sino.h"
|
|
|
|
|
+#import "RAUtils.h"
|
|
|
|
|
|
|
|
#pragma mark - Button
|
|
#pragma mark - Button
|
|
|
|
|
|
|
@@ -34,6 +36,8 @@
|
|
|
|
|
|
|
|
@property (nonatomic,assign) BOOL useGoogleMap;
|
|
@property (nonatomic,assign) BOOL useGoogleMap;
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+@property (nonatomic,strong) NSMutableDictionary* locationjson;
|
|
|
@end
|
|
@end
|
|
|
|
|
|
|
|
@implementation LocationViewController {
|
|
@implementation LocationViewController {
|
|
@@ -478,15 +482,21 @@
|
|
|
// [UIView commitAnimations];
|
|
// [UIView commitAnimations];
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
|
|
|
|
|
|
- bool bupdate=[RANetwork UpdateServiceLocation];
|
|
|
|
|
|
|
+ NSDictionary* locationJson=[RANetwork RequestServiceLocation];
|
|
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
- if(bupdate) {
|
|
|
|
|
- if (self.useGoogleMap) {
|
|
|
|
|
- [self addLocation];
|
|
|
|
|
- } else{
|
|
|
|
|
- [self addOfficeLocation];
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ int result = [locationJson[@"result"] intValue];
|
|
|
|
|
+ if(result==RESULT_TRUE) {
|
|
|
|
|
+// if (self.useGoogleMap) {
|
|
|
|
|
+// [self addLocation];
|
|
|
|
|
+// } else{
|
|
|
|
|
+ self.locationjson = [locationJson mutableCopy];
|
|
|
|
|
+ [self addOfficeLocation];
|
|
|
|
|
+// }
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -620,29 +630,52 @@
|
|
|
constant:0];
|
|
constant:0];
|
|
|
[self.view addConstraints:@[top,left,bottom,right]];
|
|
[self.view addConstraints:@[top,left,bottom,right]];
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+ NSString* path = [[RAUtils appCacheDirectory] stringByAppendingPathComponent:@"service_location.json"];
|
|
|
|
|
+ NSFileManager* fm = [NSFileManager defaultManager];
|
|
|
|
|
+ BOOL isDir = NO;
|
|
|
|
|
+ if ([fm fileExistsAtPath:path isDirectory:&isDir])
|
|
|
|
|
+ {
|
|
|
|
|
+ self.locationjson=[NSDictionary dictionaryWithContentsOfFile:path].mutableCopy;
|
|
|
|
|
+ self.locationjson[@"iscache"]=@(true);
|
|
|
[self addOfficeLocation];
|
|
[self addOfficeLocation];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- (void)addOfficeLocation {
|
|
- (void)addOfficeLocation {
|
|
|
|
|
|
|
|
[myMapView removeAnnotations:myMapView.annotations];
|
|
[myMapView removeAnnotations:myMapView.annotations];
|
|
|
- self.Locations = [ApexMobileDB get_Location];
|
|
|
|
|
|
|
+// self.Locations = [ApexMobileDB get_Location];
|
|
|
UIImage *image;
|
|
UIImage *image;
|
|
|
image = [UIImage imageNamed:@"ic_marker.png"];
|
|
image = [UIImage imageNamed:@"ic_marker.png"];
|
|
|
- for (int i = 0; i < self.Locations.count ; i ++) {
|
|
|
|
|
|
|
+
|
|
|
|
|
+ NSDictionary* objrecords = [self.locationjson objectForKey:@"records"];
|
|
|
|
|
+ int total = [[self.locationjson valueForKey:@"total"] intValue];
|
|
|
|
|
+ for(int i=0;i<total;i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ NSDictionary* objlocation = [objrecords objectForKey:[NSString stringWithFormat:@"record%d",i]];
|
|
|
|
|
+ NSString* area = [objlocation valueForKey:@"area"];
|
|
|
|
|
+ NSString* company = [objlocation valueForKey:@"company"];
|
|
|
|
|
+ NSString* city = [objlocation valueForKey:@"city"];
|
|
|
|
|
+ double longitude = [[objlocation valueForKey:@"longitude"]doubleValue] ;
|
|
|
|
|
+ double latitude = [[objlocation valueForKey:@"latitude"]doubleValue] ;
|
|
|
|
|
+ bool amap_china =[[objlocation valueForKey:@"amap_china"] boolValue] ;
|
|
|
|
|
+ CLLocationCoordinate2D c2d ;
|
|
|
|
|
|
|
|
- NSDictionary* location = self.Locations[i];
|
|
|
|
|
- NSString* area = [location valueForKey:@"area"];
|
|
|
|
|
- NSString* company = [location valueForKey:@"company"];
|
|
|
|
|
- NSString* city = [location valueForKey:@"city"];
|
|
|
|
|
- double longitude = [[location valueForKey:@"longitude"] doubleValue];
|
|
|
|
|
- double latitude = [[location valueForKey:@"latitude"] doubleValue];
|
|
|
|
|
|
|
+ NSString* country =[NSLocale currentLocale].countryCode;
|
|
|
|
|
+
|
|
|
|
|
+ if([country isEqualToString:@"CN"]&&amap_china)
|
|
|
|
|
+ {
|
|
|
|
|
+ c2d= [CLLocation CoordMars:latitude :longitude ];
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ c2d= CLLocationCoordinate2DMake(latitude, longitude);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // 创建大头针(标注)的数据模型(此处不创建视图,视图通过MKMapView的委托设置回调方法来生成的)
|
|
|
|
|
AMMapAnnotaion *ann = [[AMMapAnnotaion alloc] init];
|
|
AMMapAnnotaion *ann = [[AMMapAnnotaion alloc] init];
|
|
|
- ann.params = location;
|
|
|
|
|
- CLLocationCoordinate2D c2d = CLLocationCoordinate2DMake(latitude, longitude);
|
|
|
|
|
|
|
+ ann.params = objlocation;
|
|
|
|
|
+
|
|
|
// 指定大头针的经纬度坐标(位置)以及附加的信息
|
|
// 指定大头针的经纬度坐标(位置)以及附加的信息
|
|
|
ann.coordinate = c2d;
|
|
ann.coordinate = c2d;
|
|
|
ann.title = company;
|
|
ann.title = company;
|
|
@@ -650,8 +683,59 @@
|
|
|
|
|
|
|
|
// 将大头针数据模型添加到MKMapView上管理
|
|
// 将大头针数据模型添加到MKMapView上管理
|
|
|
[myMapView addAnnotation:ann];
|
|
[myMapView addAnnotation:ann];
|
|
|
-// break;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+//
|
|
|
|
|
+// for (int i = 0; i < self.Locations.count ; i ++) {
|
|
|
|
|
+//
|
|
|
|
|
+// NSDictionary* location = self.Locations[i];
|
|
|
|
|
+// NSString* area = [location valueForKey:@"area"];
|
|
|
|
|
+// NSString* company = [location valueForKey:@"company"];
|
|
|
|
|
+// NSString* city = [location valueForKey:@"city"];
|
|
|
|
|
+// double longitude = [[location valueForKey:@"longitude"] doubleValue];
|
|
|
|
|
+// double latitude = [[location valueForKey:@"latitude"] doubleValue];
|
|
|
|
|
+//
|
|
|
|
|
+// CLLocationCoordinate2D c2d ;
|
|
|
|
|
+//
|
|
|
|
|
+//// if let countryCode = (Locale.current as NSLocale).object(forKey: .countryCode) as? String {
|
|
|
|
|
+//// print("Code => \(countryCode)") //FR
|
|
|
|
|
+//// }
|
|
|
|
|
+// NSString* country =[NSLocale currentLocale].countryCode;
|
|
|
|
|
+//
|
|
|
|
|
+// if([country isEqualToString:@"CN"]&&([[[area lowercaseString] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] isEqualToString:@"southern china"]||[[[area lowercaseString] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] isEqualToString:@"northern china"]||[[[area lowercaseString] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] isEqualToString:@"eastern china"]))
|
|
|
|
|
+// {
|
|
|
|
|
+// c2d= [CLLocation CoordMars:latitude :longitude ];
|
|
|
|
|
+// }
|
|
|
|
|
+// else
|
|
|
|
|
+// {
|
|
|
|
|
+// c2d= CLLocationCoordinate2DMake(latitude, longitude);
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+////
|
|
|
|
|
+////
|
|
|
|
|
+//// {
|
|
|
|
|
+//// // Log.d("service location", "cn 变形: "+area);
|
|
|
|
|
+//// // Log.d("service location", "cn 变形前: "+dlatitude+","+dlongitude);
|
|
|
|
|
+//// double bd[] = GeoUtils.wgs84tobd09(dlongitude,dlatitude);
|
|
|
|
|
+//// dlongitude = bd[0];
|
|
|
|
|
+//// dlatitude = bd[1];
|
|
|
|
|
+//// // Log.d("service location", "cn 变形: "+dlatitude+","+dlongitude);
|
|
|
|
|
+////
|
|
|
|
|
+//// }
|
|
|
|
|
+//
|
|
|
|
|
+// // 创建大头针(标注)的数据模型(此处不创建视图,视图通过MKMapView的委托设置回调方法来生成的)
|
|
|
|
|
+// AMMapAnnotaion *ann = [[AMMapAnnotaion alloc] init];
|
|
|
|
|
+// ann.params = location;
|
|
|
|
|
+//
|
|
|
|
|
+// // 指定大头针的经纬度坐标(位置)以及附加的信息
|
|
|
|
|
+// ann.coordinate = c2d;
|
|
|
|
|
+// ann.title = company;
|
|
|
|
|
+// ann.subtitle = [[NSString stringWithFormat:@"%@\n%@",city,area] stringByAppendingString:NSLocalizedString(@"ask_click", nil)];
|
|
|
|
|
+//
|
|
|
|
|
+// // 将大头针数据模型添加到MKMapView上管理
|
|
|
|
|
+// [myMapView addAnnotation:ann];
|
|
|
|
|
+//// break;
|
|
|
|
|
+// }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - iOS Map Delegate
|
|
#pragma mark - iOS Map Delegate
|