English 中文(简体)
如何定期更新地图概览?
原标题:How to update Mapview Periodically?

In my application i want to update the MapView periodically and redraw the the path on map as per new location. Is it possible using MKMapView?

这是我在绘制地图和发布地图时用上的有效载荷。

- (void)viewDidLoad
 {

NSString *url=[NSString stringWithFormat:@"xxxxx.php?uid=%@&buddy_uid=%@",UserUID,buddyUid];
NSLog(@"%@",url);
NSLog(@"%@",url);
NSString * jsonString = [[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:url] encoding:NSUTF8StringEncoding error:nil];
NSLog(@"return data %@",jsonString);
NSDictionary *jsonDic = [jsonString JSONValue];
buddyLocation = [[NSString alloc] initWithFormat:@"%@,%@",[jsonDic objectForKey:@"Lattitude"],[jsonDic objectForKey:@"Longitude"]];

[super viewDidLoad];

locmanager = [[CLLocationManager alloc] init]; 
[locmanager setDelegate:self]; 
[locmanager setDesiredAccuracy:kCLLocationAccuracyBest];
//[locmanager startUpdatingLocation];
MKMapView *mapnew;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
    mapnew = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 768, 1004)];
}
else
{
    mapnew = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
}

[mapnew setDelegate:self];
[self.view addSubview:mapnew];

MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } }; 
region.center.latitude = lat1 floatValue];//22.56574;
region.center.longitude =lng1 floatValue];//73.74575;
NSString *currentLocation = [[NSString alloc] initWithFormat:@"%@,%@",lat1,lng1];
NSLog(@"%@",currentLocation);

DisplayMap *ann = [[DisplayMap alloc] init]; 
ann.title = @"Current Location";
ann.coordinate = region.center; 
[mapnew addAnnotation:ann];

NSLog(@"%@",jsonDic);
region.center.latitude = [[jsonDic objectForKey:@"Lattitude"] floatValue];//23.56574;
region.center.longitude = [[jsonDic objectForKey:@"Longitude"] floatValue];//72.74575;

ann = [[DisplayMap alloc] init]; 
ann.title = @"Buddy Location";
ann.coordinate = region.center; 

    [mapnew addAnnotation:ann];
    KMLParser *kml = [KMLParser parseKMLAtURL:[NSURL URLWithString:[NSString 
    stringWithFormat:@"https://maps.google.com/maps?saddr=%@&daddr=%@&
    output=kml",currentLocation,buddyLocation]]]; 
    NSArray *overlays = [kml overlays];
    [mapnew addOverlays:overlays];

    MKMapRect flyTo = MKMapRectNull;
    for (id <MKOverlay> overlay in overlays) 
    {
        if (MKMapRectIsNull(flyTo)) 
        {
            flyTo = [overlay boundingMapRect];
        }
        else 
        {
            flyTo = MKMapRectUnion(flyTo, [overlay boundingMapRect]);
        }
    }

    mapnew.visibleMapRect = flyTo;
    [mapnew release];
    mapnew =nil;
}

 }
 -(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay 
 {        
MKPolylineView *line = [[[MKPolylineView alloc] initWithPolyline:overlay] autorelease]; 
line.strokeColor = [UIColor blueColor]; 
line.lineWidth =2.0;
return line;
 }
最佳回答

只有当观点被装满时,才采用“观点”方法。 之后,它只能控制连续访问的“观察”等方法。 你们必须做的是,如何掌握从电离层数据上划出的位置数据,并使之成为一个阵列或物体。 并称之为将这些材料重新编成地图的方法,即删除以前的说明或超支,然后添加新的内容。 你们可以使用时间或像时间一样的固定间隔使用这种方法。 我猜想这样做会有助益。

问题回答

暂无回答




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签