//
//  LocationViewController.m
//  Apex Mobile
//
//  Created by Ray on 14-2-26.
//  Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
//

#import "LocationViewController.h"
//#import <GoogleMaps/GoogleMaps.h>

@interface LocationViewController ()
//@property (strong,nonatomic) NSString* locations ;
@end

@implementation LocationViewController{
    GMSMapView *mapView_;
}
- (BOOL)shouldAutorotate
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.showNavigation = false;
        // Custom initialization
    }
    return self;
}
//- (void)viewWillAppear:(BOOL)animated
//{
//    if(self.showNavigation==false)
//        [self.navigationController setNavigationBarHidden:true];
//}
//- (void)viewWillDisappear:(BOOL)animated
//{
//    if(self.showNavigation==false)
//        [self.navigationController setNavigationBarHidden:false];
//}
- (void)viewDidLoad
{
    [super viewDidLoad];
    [self updateLocation];
    // Create a GMSCameraPosition that tells the map to display the
    // coordinate -33.86,151.20 at zoom level 6.
    //    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
    //                                                            longitude:151.20
    //                                                                 zoom:6];
    //    mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
    //    mapView_.myLocationEnabled = YES;
    //    self.view = mapView_;
    //
    //    // Creates a marker in the center of the map.
    //    GMSMarker *marker = [[GMSMarker alloc] init];
    //    marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
    //    marker.title = @"Sydney";
    //    marker.snippet = @"Australia";
    //    marker.map = mapView_;
    
    

    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:39.833333
                                                            longitude:-98.3583333
                                                                 zoom:2.5
                                                              bearing:0
                                                         viewingAngle:0];
    mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
    mapView_.myLocationEnabled = YES;
    mapView_.delegate = self;
    self.view = mapView_;
    
    
    
    
    //   NSString *locations =@"Apex Maritime Co. (ORD) Inc.';'Chicago, IL\nUnited States';'42.051169,-88.0317029';'1900 E. Golf Road, Suite# 1105 Schaumburg, IL 60173';'Tel:+1 630 227-9818';'Fax:+1 630 227-9808';'Contact:\nSteve Yeh\nAileen Hsieh';'Email:\nsteve.yeh@apexshipping.com\naileen.hsieh@apexshipping.com';'Apex Maritime Co. (Hou) Inc.';'Houston, TX\nUnited States';'29.797022,-95.528827';'9610 Long Point Rd., Suite# 320 Houston, TX 77055';'Tel:+1 832 649-8198';'Fax:+1 832 649-8194';'Contact:\nAndy Pan\nTong Tong';'Email:\nandy.pan@apexshipping.com\ntong.tong@apexshipping.com';'Apex Maritime Co. (LAX) Inc.';'Los Angeles, CA\nUnited States';'34.0092709,-117.8463627';'565 Brea Canyon Road, Suite D Walnut, CA 91789';'Tel:+1 909 594-8828';'Fax:+1 909 594-9199';'Contact:\nVincent Luo\nSteven Chow';'Email:\nvincent.luo@apexshipping.com\nsteven.chow@apexshipping.com';'Apex Shipping Co., (NYC) Inc.';'New York, NY\nUnited States';'40.668404,-73.708329';'20 North Central Ave., 2nd FL, Suite# D Valley Stream, NY 11580';'Tel:516-200-9500';'Fax:516-200-9510';'Contact:\nWei Sun\nIrene Tseng';'Email:\nwei.sun@apexshipping.com\nirene.tseng@apexshipping.com';'Apex Maritime Co., Inc.';'San Francisco, CA\nUnited States';'37.646374,-122.398847';'206 Utah Ave. So. San Francisco, CA 94080';'Tel:650-589-2575';'Fax:650-589-8861';'Contact:\nJames Chu\nEsther Hui';'Email:\njames.chu@apexshipping.com\nesther.hui@apexshipping.com';'Apex Maritime Co., (PNW) Inc.';'Seattle, WA\nUnited States';'47.467763,-122.2321';'1107 S. W. Grady Way, Building B, Suite #110 Renton, WA 98055';'Tel:206-241-0771';'Fax:206-241-0823';'Contact:\nMike Langley\nRobert Bleck';'Email:\nmike.langley@apexshipping.com\nrobert.bleck@apexshipping.com';'Apex Maritime (Thailand) Co., Ltd.';'Bangkok, Thailand\nSoutheast Asia';'13.7308333,100.5241667';'138 Boonmitr Bldg., 12th Fl. Room B3, Silom Rd., Suriyawongse, Bangrak, Bangkok 10500';'Tel:+66 2 2634-3899 (Auto)';'Fax:+66 2 2634-3055\n66 2 2634-3056';'Contact:\nThikarn\nJaruwan\nSantana';'Email:\nthikarn@apexmaritime.co.th\njaruwan@apexmaritime.co.th\nsantana@apexmaritime.co.th';'PT. Apex Maritim Indonesia';'Cirebon, Indonesia\nSoutheast Asia';'-6.7166667,108.5666667';'HOTEL BUMI ASIH 2 ND FLOOR # 209 JL. WAHIDIN NO. 52 CIREBON';'Tel:+62 231 207278';'Fax:+62 231 207287';'Contact:\nSOEGIHARTO';'Email:\napex_cirebon@apex-indonesia.com';'Apex Vietnam';'Da Nang, Vietnam\nSoutheast Asia';'16.0641802,108.1873407';'3 FL, 39-41 Quang Trung Street Hai Chau Dist., Danang City, Vietnam';'Tel:+84 511 3896403';'Fax:+84 511 3823563';'Contact:\nMs. LAI';'Email:\ndanang@apexshipping.com.vn';'Apex Vietnam';'Haiphong, Vietnam\nSoutheast Asia';'20.861361,106.679802';'6th FL, 452 Le Thanh Tong Street Ngo Quyen District, Haiphong City, Vietnam';'Tel:+84 31 3750152';'Fax:+84 31 3836796';'Contact:\nMr. Nguyen Nhat Tan\nMr. Nguyen Nhat Huy';'Email:\nhaiphong@apexshipping.com.vn';'Apex Vietnam';'Hanoi, Vietnam\nSoutheast Asia';'21.0333333,105.85';'2nd FL. 108 Lo Duc Street. Hai Ba Trung District. Hanoi City, Vietnam';'Tel:+84 4 3971-9128';'Fax:+84 4 3971-9129';'Contact:\nMs. Le Thu Phuong';'Email:\nhanoi@apexshipping.com.vn';'Maritime Bank Tower ';'Ho Chi Minh City, Vietnam\nSoutheast Asia';'10.7685558,106.7012357';'Maritime Bank Tower 22th floor, room 02 180-192 Nguyen Cong Tru St., District 1 Hochiminh City, Vietnam';'Tel:+84 8 3914 2224';'Fax:+84 8 3914 3228\n3229';'Contact:\nThomas Phong';'Email:\nthomas@apexshipping.com.vn';'PT. Apex Shipping Indonesia';'Jakarta, Indonesia\nSoutheast Asia';'-6.225246,106.597423';'JIn. Bulevar Gajah Mada No. 2087 Lippo Cyberpark, Lippo Karawaci Tangerang 15811, Indonesia';'Tel:+62 21 558-2427';'Fax:+62 21 5577-1362';'Contact:\nNigolas Sjahputra\nUmi';'Email:\nnigolas@apex-indonesia.com\numi@apex-indonesia.com';'Apex Container Line (M) SDN BHD';'Malaysia\nSoutheast Asia';'1.3814563,103.4800838';'Suite 23A-05, level 23A, City Square, Jln Wong Ah Fook, 80000 Johor Bahru, Hohor, West Malaysia.';'Tel:(60) 7 222-2248 ( 6 lines)';'Fax:(60) 7 222-2278 (2 lines)';'Contact:\nFong Yee Chong';'Email:\nchloe.chong@apexshipping.com.my';'PT. Apex Maritim Indonesia';'Semarang, Indonesia\nSoutheast Asia';'-7.0016889,110.4331614';'RUKO METRO PLAZA JL. MT. HARYONO 970 BLOK C-7';'Tel:+62 24 844-7555';'Fax:+62 24 844-7666';'Contact:\nM. AYUB';'Email:\nm_ayub@apex-indonesia.com';'PT. Apex Maritim Indonesia';'Surabaya, Indonesia\nSoutheast Asia';'-7.289166,112.734398';'RUKO PERMATA BINTORO JL. TAMAN KETAMPON NO. 87 SURABAYA �C INDONESIA';'Tel:+62 31 566-1144';'Fax:+62 31 566-8289\n+62 31 566-9933';'Contact:\nIKA';'Email:\nika_setiawan@apex-indonesia.com';'Apex Maritime (Dalian) Co., Ltd.';'Dalian, China\nNorthern China';'38.9218515,121.6561693';'Room 201 No.1-3 No.112 Zhigong Street, Zhongshan Dis. Dalian, China';'Tel:+86 411 88866116 (Main)';'Fax:+86 411 82717900 (OP Dep.)';'Contact:\nWillis Yan �C +86 411 88866118\nJulia Guan �C +86 411 88866136';'Email:\nwillis.yan@apexshipping.com.cn\njulia.guan@apexshipping.com.cn';'Apex Maritime (Lianyungang) Co., Ltd.';'Lianyungang, China\nNorthern China';'34.596544,119.221282';'Room 715, No. 1 Street Building. Wangtian Haicheng Square. Xugou Lianyungang, Jiangsu, China';'Tel:+86 518 8223-3218\n+86 518 8223-3219';'Fax:+86 518 8223-3220';'Contact:\nZena Zheng';'Email:\nzena.zheng@apexshipping.com.cn';'Qingdao Apex Shipping Co., Ltd.';'Qingdao, China\nNorthern China';'36.0565576,120.3709705';'Suite 1903, No. 5 Donghai West Road Qingdao City, 266071, Shandong Province, China';'Tel:+86 532 85708982, 85708595, 85708109, 81979902';'Fax:+86 532 85708110';'Contact:\nFrank Song\nJennifer Liu';'Email:\nfrank.song@apexshipping.com.cn\njennifer.liu@apexshipping.com.cn';'Apex Maritime (Tianjin) Co., Ltd.';'Tianjin, China\nNorthern China';'39.1186127,117.1973693';'Room 3506, The Exchange North Tower, 189 Nanjin Rd. Tianjin, China';'Tel:+86 22 5886 3000';'Fax:+86 22 5886 3006\n5886 3008';'Contact:\nLucy Diao\nMandy Miao';'Email:\nlucy.diao@apexshipping.com.cn\nmandy.miao@apexshipping.com.cn';'Apex Maritime (Xian) Co., Ltd.';'Xian, China\nNorthern China';'34.2368419,108.8988572';'Room 912, Building C, Fortune Center II Gao Xin Third Rd., Hi-Tech Development Zone Xian City, Shaanxi Province,China 710075';'Tel:+86 29 65676809\n65676810\n65676811\n65676812';'Fax:+86 29 65676805';'Contact:\nKaren Huang';'Email:\nkaren.huang@apexshipping.com.cn';'Apex Maritime (Yantai) Co., Ltd.';'Yantai, China\nNorthern China';'37.5422926,121.3947602';'Room 2301, Huaxia Media Mansion, No. 53 North Ave. Yantai City,Shandong Province,China 264001';'Tel:+86 535 623-1345';'Fax:+86 535 623-4630';'Contact:\nJoey Yan';'Email:\njoey.yan@apexshipping.com.cn';'Apex Maritime (Chongqing) Co., Ltd.';'Chongqing, China\nEastern China';'29.5716184,106.531413';'Room 6, Floor 23, South Tower, Shijiyinghuang Building No. 38, North Jianxin Rd, Jiangbei District Chongqing 400020, China';'Tel:+86 23 8819 2009';'Fax:+86 23 8819 2036';'Contact:\nCindy Zeng\nLisa Xie';'Email:\ncindy.zeng@apexshipping.com.cn\nlisa.xie@apexshipping.com.cn';'Apex Maritime (Nanjing) Co., Ltd.';'Nanjing, China\nEastern China';'32.043114,118.789098';'Room D2, 18th Floor No.89 Hanzhong Road, Nanjing 210029, Jiangsu, China';'Tel:+86 25 84845871';'Fax:+86 25 84845879';'Contact:\nWinter Zhu';'Email:\nwinter.zhu@apexshipping.com.cn';'Apex Maritime (Ningbo) Co., Ltd.';'Ningbo, China\nEastern China';'29.8651695,121.5573647';'Rm 902, China Life Building No. 777 Lingqiao Road Ningbo 315010, China';'Tel:+86 574 8768 6310';'Fax:+86 574 8768 6314';'Contact:\nMr. Jason Sun';'Email:\njason.sun@apexshipping.com.cn';'Apex Maritime (Shanghai) Co., Ltd.';'Shanghai, China\nEastern China';'31.1668495,121.5430195';'RM 1211, WangJiao Plaza, 175, East Yianan Road, Shanghai 200002, China';'Tel:+86 21 6336 2020';'Fax:+86 21 53930630, 63563585, 63269809';'Contact:\nHali Huang';'Email:\nhali.huang@apexshipping.com.cn\njennifer.yu@apexshipping.com.cn';'Apex Maritime (Wuhan) Co., Ltd.';'Wuhan, China\nEastern China';'30.5952142,114.2977709';'Rm 1201, Truroll Plaza Wusheng Road Wuhan 430030, China.';'Tel:+86 27 8551 8817';'Fax:+86 27 8551 8882';'Contact:\nKatherine Lee';'Email:\nkatherine.lee@apexshipping.com.cn';'Apex Maritime (Fuzhou) Co., Ltd.';'Fuzhou, China\nSouthern China';'26.085417,119.294304';'Room A, 10\nF, Block No. 2, Hongyangxincheng Building No. 118 East Yangqiao Road Fuzhou 350001, China';'Tel:+86 591 87275810';'Fax:+86 591 87275890';'Contact:\nHelen Zhang';'Email:\nhelen.zhang@apexshipping.com.cn';'Apex Maritime (Guangzhou)';'Guangzhou, China\nSouthern China';'23.1345288,113.3079438';'Room 13B, Tower A Guangdong International Building No. 339 Huanshi Dong Road, Yuexiu District Guangzhou City, China';'Tel:+86-20-2237-8671';'Fax:+86-20-2237-8677';'Contact:\nBondy Zhang';'Email:\nbondy.zhang@apexshipping.com.cn';'Apex Maritime (HK) Co., Ltd.';'Hong Kong\nSouthern China';'22.281076,114.175695';'Room 1407-08, Harbour Centre 25 Harbour Rd. Wanchai, Hong Kong';'Tel:852-3188-9666';'Fax:852-3188-9555';'Contact:\nMartin Siu\nAndy Wong';'Email:\nmartin.siu@apexshipping.com.hk\nandy.wong@apexshipping.com.hk';'Apex Maritime (Shenzhen) Co., Ltd.';'Shenzhen, China\nSouthern China';'22.5427078,114.0710992';'Room 802, 8\nF., New China Insurance Edifice Mintian Rd., Futian District Shenzhen City, China 518026';'Tel:+86-755-8826-4001';'Fax:+86-755-8826-4014';'Contact:\nJames Zhuo\nShirley Xia';'Email:\njames.zhuo@apexshipping.com.cn\nshirley.xia@apexshipping.com.cn';'Apex Maritime (XMN) Co., Inc.';'Xiamen, China\nSouthern China';'24.462809,118.075456';'24H, International Plaza No. 8 Lujiang Rd. Xiamen 361001, China';'Tel:+86-592-261-8066';'Fax:+86-592-261-8070';'Contact:\nHelen Zhang';'Email:\nhelen.zhang@apexshipping.com.cn';'Apex Maritime (HK) Co., Ltd. (Zhongshan Branch)';'Zhongshan, China\nSouthern China';'22.501821,113.397235';'Room 07-08, 10\nF., Da Dong Yu Commerce Center Boai 5 Road, Zhongshan City, PRC';'Tel:+86 760 2 3889966\n+86 760 2 3889961';'Fax:+86 760 2 3889969';'Contact:\nAndy Shan';'Email:\nandy.shan@apexshipping.com.cn';'Apex Maritime India Pvt. Ltd.';'New Delhi\nIndia';'28.6244285,77.1349161';'CB 385 B First Floor, Ring Road Naraina, New Delhi 110028';'Tel:+91 98 11 123333';'Fax:';'Contact:\n';'Email:\ngt@apexshipping.in';'Apex Shipping B.V.';'Rotterdam, Netherlands\nEurope';'51.8637994,4.4348681';'Achterdijk 51-55 3161 EB Rhoon The Netherlands';'Tel:+31 10 8208801';'Fax:+31 10 8208802';'Contact:\nRon Reuver\nJohn Born';'Email:\nron.reuver@apexshipping.nl\njohn.born@apexshipping.nl";
    
    //  NSArray *parts =[locations componentsSeparatedByString:NSLocalizedString(@"';'", nil)];
    
    
    [self addLocation];
    
    
    /*       map.setInfoWindowAdapter(new CustomWindowAdapter());
     map.moveCamera(CameraUpdateFactory.newCameraPosition(US));
     map.setOnMarkerClickListener(this);
     map.setOnInfoWindowClickListener(this);*/
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)mapView:(GMSMapView *)mapView
didTapInfoWindowOfMarker:(GMSMarker *)marker
{
    DebugLog(@"tap info window");
    //    id ud = marker.userData;
    self.params = marker.userData;
    
    [self addUnknown];
    
//    LocationDetailViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"LocationDetailViewController"];
//    ViewController.params = self.params;
//    self.aBNewPersonNav = [[UINavigationController alloc] initWithRootViewController:ViewController] ;
//    [self presentViewController:self.aBNewPersonNav animated:YES completion:^{
//        
//    }];
    
    
//    [self presentViewController:self.aBNewPersonNav animated:YES];

    
//
//    
//
//    [self.navigationController pushViewController:ViewController animated:YES];
//    [self performSegueWithIdentifier:@"DETAIL" sender:self];
    
}
- (void)addUnknown
{
    
    
    
    //    NSString* area = [self.params valueForKey:@"area"];
    NSString* company = [self.params valueForKey:@"company"];
    NSString* city = [self.params valueForKey:@"city"];
    //    double longitude = [[self.params valueForKey:@"longitude"] doubleValue];
    //    double latitude = [[self.params valueForKey:@"latitude"] doubleValue];
    NSString* address = [self.params valueForKeyPath:@"address"];
    NSString* telephone = [self.params valueForKeyPath:@"telephone"];
    NSString* fax = [self.params valueForKeyPath:@"fax"];
    //    NSString* contact = [self.params valueForKeyPath:@"contact"];
    NSString* email = [self.params valueForKeyPath:@"email"];
    
    
    
    
    
    
    
    CFStringRef cfscompany = CFStringCreateWithCString( kCFAllocatorDefault, [company UTF8String], kCFStringEncodingUTF8);
    //    CFStringRef cfsaddress = CFStringCreateWithCString( kCFAllocatorDefault, [address UTF8String], kCFStringEncodingUTF8);
    //    CFStringRef cfsaddress = CFStringCreateWithCString( kCFAllocatorDefault, [address UTF8String], kCFStringEncodingUTF8);
    //    CFStringRef cfsaddress = CFStringCreateWithCString( kCFAllocatorDefault, [address UTF8String], kCFStringEncodingUTF8);
    //    CFStringRef cfsaddress = CFStringCreateWithCString( kCFAllocatorDefault, [address UTF8String], kCFStringEncodingUTF8);
    
    CFErrorRef error =NULL;
    ABRecordRef personRef=ABPersonCreate();
    
    
    NSData *dataRef = UIImagePNGRepresentation([UIImage imageNamed:@"apex512"]);
    ABPersonSetImageData(personRef, CFBridgingRetain(dataRef), &error);
    //    ABAddressBookAddRecord(iPhoneAddressBook, newPerson, &error);
    
    ABRecordSetValue(personRef, kABPersonOrganizationProperty, cfscompany, &error);
    ABMutableMultiValueRef urlMultiValue = ABMultiValueCreateMutable(kABMultiStringPropertyType);
    ABMultiValueAddValueAndLabel(urlMultiValue,@"http://www.apexshipping.com", kABPersonHomePageLabel, NULL);
    ABRecordSetValue(personRef, kABPersonURLProperty, urlMultiValue, &error);
    
    
    ABMutableMultiValueRef multiaddress=ABMultiValueCreateMutable(kABMultiStringPropertyType);
    //电话号码属于具有多个值的项（除此还有email、地址类）
    NSMutableDictionary *addressDictionary = [[NSMutableDictionary alloc] init];
    [addressDictionary setObject:address forKey:(NSString *) kABPersonAddressStreetKey];
    [addressDictionary setObject:city forKey:(NSString *)kABPersonAddressCityKey];
    //    [addressDictionary setObject:@"IL" forKey:(NSString *)kABPersonAddressStateKey];
    //    [addressDictionary setObject:@"60654" forKey:(NSString *)kABPersonAddressZIPKey];
    ABMultiValueAddValueAndLabel(multiaddress, CFBridgingRetain(addressDictionary), kABWorkLabel, NULL);
    
    
    // CFStringRef cfsaddress = CFStringCreateWithCString( kCFAllocatorDefault, [address UTF8String], kCFStringEncodingUTF8);
    //        ABMultiValueAddValueAndLabel(multiaddress, cfsaddress, kABWorkLabel, NULL);
    ABRecordSetValue(personRef, kABPersonAddressProperty, multiaddress, &error);
    
    
    ABMutableMultiValueRef multiemail=ABMultiValueCreateMutable(kABMultiStringPropertyType);
    //电话号码属于具有多个值的项（除此还有email、地址类）
    NSArray* arremail = [email componentsSeparatedByString:NSLocalizedString(@"\r\n", nil)];
    for(int i=0;i<arremail.count;i++)
    {
        ABMultiValueAddValueAndLabel(multiemail, CFStringCreateWithCString( kCFAllocatorDefault, [arremail[i] UTF8String], kCFStringEncodingUTF8), kABWorkLabel, NULL);
    }
    ABRecordSetValue(personRef, kABPersonEmailProperty, multiemail, &error);
    
    ABMutableMultiValueRef multiphone=ABMultiValueCreateMutable(kABMultiStringPropertyType);
    //电话号码属于具有多个值的项（除此还有email、地址类）
    NSArray* arrphone = [telephone componentsSeparatedByString:NSLocalizedString(@"\r\n", nil)];
    for(int i=0;i<arrphone.count;i++)
    {
        ABMultiValueAddValueAndLabel(multiphone, CFStringCreateWithCString( kCFAllocatorDefault, [arrphone[i] UTF8String], kCFStringEncodingUTF8), kABWorkLabel, NULL);
    }
    
    NSArray* arrfax = [fax componentsSeparatedByString:NSLocalizedString(@"\r\n", nil)];
    for(int i=0;i<arrfax.count;i++)
    {
        ABMultiValueAddValueAndLabel(multiphone, CFStringCreateWithCString( kCFAllocatorDefault, [arrfax[i] UTF8String], kCFStringEncodingUTF8), kABPersonPhoneWorkFAXLabel, NULL);
    }
    ABRecordSetValue(personRef, kABPersonPhoneProperty, multiphone, &error);
    
    
    
    ABUnknownPersonViewController *unknown=[[ABUnknownPersonViewController alloc]init];
    unknown.displayedPerson = personRef;
    unknown.unknownPersonViewDelegate = self;
    unknown.allowsActions = true;
    
    ABAddressBookRef addressBook = ABAddressBookCreate();
    //    CFStringRef cfName = CFSTR("小明");
    NSArray *people = (__bridge NSArray *)(ABAddressBookCopyPeopleWithName(addressBook, cfscompany));
    
    if(people.count>0)
        unknown.allowsAddingToAddressBook = false;
    //    unknown.displayedPerson=person;
    //    unknown.allowsAddingToAddressBook=YES;//允许添加
    
    //    ABNewPersonViewController *npvc = [[ABNewPersonViewController alloc] init] ;
    //    //  npvc.navigationItem.leftBarButtonItem = BARBUTTON(@"取消", @selector(addNewBackAction:));
    //    //  self.aBNewPersonNav = [[UINavigationController alloc] initWithRootViewController:npvc] ;
    //    npvc.displayedPerson = personRef;
    //    npvc.newPersonViewDelegate = self;
    // [self presentModalViewController:self.aBNewPersonNav animated:YES];
    
   
    self.aBNewPersonNav = [[UINavigationController alloc] initWithRootViewController:unknown] ;
    UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"close", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onCloseClick:)];
    //    closeButton.title = @"Close";
    
    unknown.navigationItem.leftBarButtonItem = closeButton;
    
    unknown.navigationItem.title =[self.params valueForKey:@"company"];
    [self presentViewController:self.aBNewPersonNav animated:YES completion:^{
        
    }];

    
//    [self.navigationController pushViewController:unknown animated:YES];
    
    
    
}
- (void)onCloseClick:(UIButton *)sender {
    [self.aBNewPersonNav dismissViewControllerAnimated:true completion:^{
        ;
    }];
}

-(void) addLocation
{
    
    [mapView_ clear];
    self.Locations = [ApexMobileDB get_Location];
    UIImage *image;
    image = [UIImage imageNamed:@"ic_marker.png"];
    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];
        //                NSString* address = [location valueForKeyPath:@"address"];
        //                NSString* telephone = [location valueForKeyPath:@"telephone"];
        //                NSString* fax = [location valueForKeyPath:@"fax"];
        //                NSString* contact = [location valueForKeyPath:@"contact"];
        //                NSString* email = [location valueForKeyPath:@"email"];
        
        
        //                NSString *markertext = parts[i];
        //                NSString *city = parts[i + 1];
        //                NSString *postext = parts[i + 2];
        //                NSArray *point = [postext componentsSeparatedByString:NSLocalizedString(@",", nil)];//postext.split(",");
        //
        //                NSString *address = parts[i+3];
        //                NSArray *tel = parts[i+4];
        //                NSArray *fax = parts[i+5];
        //                NSArray *contact = parts[i+6];
        //                NSArray *email = parts[i+7];
        
        //                NSMutableDictionary* params = [[NSMutableDictionary alloc]init];
        //                [params setObject:markertext forKey:@"name"];
        //                [params setObject:address forKey:@"addr"];
        //                [params setObject:telephone forKey:@"tel"];
        //                [params setObject:fax forKey:@"fax"];
        //                [params setObject:contact forKey:@"contact"];
        //                [params setObject:email forKey:@"email"];
        
        //    // Creates a marker in the center of the map.
        GMSMarker *marker = [[GMSMarker alloc] init];
        marker.position = CLLocationCoordinate2DMake(latitude,longitude);
        marker.title = company;
        //        NSString* snippet = [city stringByAppendingString:@"\n Click for more detail"];
        marker.snippet = [[NSString stringWithFormat:@"%@\n%@",city,area] stringByAppendingString:NSLocalizedString(@"ask_click", nil)];
        marker.map = mapView_;
        marker.userData = location;
        marker.icon = image;
        
        DebugLog(@"create marker title:%@   snippet:%@",marker.title,marker.snippet);
        
        
    }
}
-(void) updateLocation
{
    
    //    [self.params setValue:[NSString stringWithFormat:@"%ld",self.offset] forKey:@"offset"];
    //    self.mum.center = self.view.center;
    //
    //    NSTimeInterval animationDuration = 0.30f;
    //    [UIView beginAnimations:@"ResizeView" context:nil];
    //    [UIView setAnimationDuration:animationDuration];
    //    self.prepageButton.enabled=false;
    //    self.nextpageButton.enabled=false;
    //    self.mum.hidden = false;
    //    self.grid.hidden = true;
    //
    //    [UIView commitAnimations];
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        
        bool bupdate=[ApexMobileNetwork UpdateServiceLocation];
        
        dispatch_async(dispatch_get_main_queue(), ^{
            if(bupdate)
                [self addLocation];
            
            
            //            if(bupdate==true)
            //            {
            //
            //            }
            //            else
            //            {
            //
            //            }
            //            if(self.recordCount>=0)
            //            {
            //                if(self.recordCount<2000)
            //                    self.countView.title = [NSString stringWithFormat:@"%ld records",self.recordCount];
            //                else
            //                    self.countView.title = @"2000+ records";
            //            }
            //            else
            //            {
            //                self.countView.title = @"Net error!";
            //            }
            //            if(self.offset<self.pageData.get_count||self.offset==0)
            //                self.prepageButton.enabled=false;
            //            else
            //                self.prepageButton.enabled=true;
            //            if(self.offset+self.pageData.get_count>=self.recordCount)
            //                self.nextpageButton.enabled=false;
            //            else
            //                self.nextpageButton.enabled=true;
            //            [self.grid initgrid :self.pageData];
            //
            //            CGPoint p = self.grid.frame.origin;
            //
            //
            //            self.mum.hidden = true;
            //            self.grid.hidden = false;
            //            [UIView commitAnimations];
            
        });
    });
}

//- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
//    
//    if ([[segue identifier] isEqualToString:@"DETAIL"]) {
//        
//        
//        
//        
//        LocationDetailViewController *ViewController = segue.destinationViewController;
//        
//        ViewController.params = self.params;
//    }
//}
//- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker {
//  //  if (marker == melbourneMarker_) {
//    UILabel * ret = [[UILabel alloc] init];
//    ret.text = @"textazaaaaaaa";
//    ret.backgroundColor = [UIColor whiteColor];
//    [ret sizeToFit];
//    return ret;
//        return [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"first"]];
//   // }
//    
//    return nil;
//}
@end
