2011-10-21 14 views
10

मेरे पास नक्शादृश्य ठीक काम कर रहा है, लेकिन मानचित्र पर रखे गए पिन का शीर्षक संयुक्त राज्य अमेरिका है। मैं इस शीर्षक को कैसे बदल सकता हूं?एमकेप्लेसमार्क पिन शीर्षक

MKCoordinateRegion thisRegion = {{0.0,0.0}, {0.0,0.0}}; 

     thisRegion.center.latitude = 22.569722; 
     thisRegion.center.longitude = 88.369722; 

     CLLocationCoordinate2D coordinate; 
     coordinate.latitude = 22.569722; 
     coordinate.longitude = 88.369722; 

     thisRegion.center = coordinate; 

     MKPlacemark *mPlacemark = [[[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:nil] autorelease]; 

     [mapView addAnnotation:mPlacemark]; 
     [mapView setRegion:thisRegion animated:YES]; 

उत्तर

0

चेकआउट MKAnnotation प्रोटोकॉल है, जो MKPlacemark के अनुरूप है। आपको शीर्षक सेट करने में सक्षम होना चाहिए।

http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKAnnotation_Protocol/Reference/Reference.html

http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKPlacemark_Class/Reference/Reference.html

13

काफी पुराने सवाल, लेकिन शायद ही समस्या पर किसी और stumbles (मैंने किया था के रूप में):

मानचित्र के एनोटेशन के लिए एक MKPlacemark न जोड़ें; इसके बजाय MKPointAnnotation का उपयोग करें। इस वर्ग में शीर्षक और उपशीर्षक गुण हैं जो केवल पढ़ने योग्य नहीं हैं। जब आप उन्हें सेट करते हैं, तो मानचित्र पर एनोटेशन तदनुसार अपडेट किया जाता है - और शायद यह वही है जो आप चाहते हैं।

अपने कोड में MKPointAnnotation का उपयोग करने के लिए, लाइनों है कि आवंटन की जगह और इस कोड के साथ MKPlacemark जोड़ें:

MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init]; 
annotation.coordinate = coordinate; 
annotation.title = NSLocalizedString(@"Dropped Pin", 
            @"Title of a dropped pin in a map"); 
[mapView addAnnotation:annotation]; 

आप शीर्षक और उपशीर्षक गुण बाद में कभी भी, भी सेट कर सकते हैं। उदाहरण के लिए, यदि आपके पास एक एसिंक्रोनस एड्रेस क्वेरी चल रही है, तो जैसे ही पता उपलब्ध हो, आप उपशीर्षक को एनोटेशन के पते पर सेट कर सकते हैं।

5

कोड नीचे आईओएस 5.1 में

-(void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { 

CLGeocoder *geocoder = [[CLGeocoder alloc] init]; 

// Apple recommendation - if location is older than 30s ignore 
// Comment out below during development 
/* if (fabs([newLocation.timestamp timeIntervalSinceDate:[NSDate date]]) > 30) { 
    NSLog(@"timestamp"); 
    return; 
}*/ 

CLLocation *coord = [[CLLocation alloc] initWithLatitude:locationManager.location.coordinate.latitude longitude:locationManager.location.coordinate.longitude];        
[geocoder reverseGeocodeLocation:coord completionHandler:^(NSArray *placemarks, NSError *error) { 

    if (error) { 
     NSLog(@"Geocode failed with error"); 
    } 

    // check for returned placemarks 
    if (placemarks && placemarks.count > 0) { 
     CLPlacemark *topresult = [placemarks objectAtIndex:0]; 
     MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init]; 
     annotation.coordinate = locationManager.location.coordinate; 
     annotation.title = NSLocalizedString(@"You are here", @"Title"); 
     annotation.subtitle = [NSString stringWithFormat:@"%@, %@", [topresult subAdministrativeArea], [topresult locality]]; 
     [self.mapView addAnnotation:annotation]; 
    } 
}]; 
} 
CLGeocoder का उपयोग कर एक नक्शे पर एक एनोटेशन रखने दर्शाता

 संबंधित मुद्दे

  • कोई संबंधित समस्या नहीं^_^