Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6689441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:31:10+00:00 2026-05-26T05:31:10+00:00

In my application i want to update the MapView periodically and redraw the the

  • 0

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?

This is my didload metho for drawing and annotation on mapview.

- (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;
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:31:11+00:00Added an answer on May 26, 2026 at 5:31 am

    ViewDidiLoad method is called only once when the view is loaded After that it would only give control to methods like viewWillappear etc on successive visits . What you have to do is seperate the method which parses the location data from viewDidLoad, and make it set an array or objects . And call the method to reset these contents on Map i.e. remove previous annotations or overlay and then add new ones . problem solved. You could call these method at fixed interval using timer or something like that. I guess this should help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application with map and want to zoom to the current location,
Mates, I want to update a role description using my application I don´t know
I am using PyGTK to build a GUI application. I want to update the
For my new iPhone Application (Xcode 4.3.2), i want to update my UITable (xml
I want to update my node application on production, but users are using it
Periodically my application must update the database. This update may not be automatic. When
i have ios application with xcdatamodeld, i want update some data so need a
I have developed a windows forms c# application, i just want update items in
I want to update a Application on Android App Market but the problem is
I want to update an ASP .NET web application (including web.config file changes and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.