Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-10-2010, 04:14 PM   #1 (permalink)
www.Alexj17.com
 
Alexj17's Avatar
 
Join Date: May 2009
Location: Liverpool, England
Posts: 181
Alexj17 is on a distinguished road
Send a message via Skype™ to Alexj17
Default Map Overlays

Hey All

Ive done my best to google this and fix it myself but i just cant.

My problem is drawing multiple overlays only once.

I have a timer which checks my PHP every 3 seconds and gets the co-ords to draw the circle. In my time i have this....

Code:
    for(int i = 0; i < [Details count]; i++)
    {
        NSDictionary *dict2 = [Details objectAtIndex:i];
        
        float Mlat = [[dict2 objectForKey:@"missile_lat"] floatValue];
        float Mlong = [[dict2 objectForKey:@"missile_long"] floatValue];
        float radius = [[dict2 objectForKey:@"missile_blast_meters"] floatValue];
        
        CLLocationCoordinate2D seoul = {Mlat,Mlong};
        MKCircle* circle = [MKCircle circleWithCenterCoordinate:seoul radius:radius];
        [myMap addOverlay:circle];
    }
Then i have the code to draw a circle.

Code:
-(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id)overlay{
    MKCircleView* circleView = [[[MKCircleView alloc] initWithOverlay:overlay] autorelease];
    circleView.strokeColor = [UIColor redColor];
    circleView.lineWidth = 1.0;
    circleView.fillColor = [UIColor colorWithRed:(255 / 255.0) green:(0 / 255.0) blue:(0 / 255.0) alpha: 0.1];
    return circleView;
}
Now the problem i am having is that every 3 seconds the circles are drawn, they are not being removed then redrawn and they are not being checked if duplicates.

I need some help please...

Alex
Alexj17 is offline   Reply With Quote
Old 08-10-2010, 09:20 PM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by Alexj17 View Post
Hey All

Ive done my best to google this and fix it myself but i just cant.

My problem is drawing multiple overlays only once.

I have a timer which checks my PHP every 3 seconds and gets the co-ords to draw the circle. In my time i have this....

Code:
    for(int i = 0; i < [Details count]; i++)
    {
        NSDictionary *dict2 = [Details objectAtIndex:i];
        
        float Mlat = [[dict2 objectForKey:@"missile_lat"] floatValue];
        float Mlong = [[dict2 objectForKey:@"missile_long"] floatValue];
        float radius = [[dict2 objectForKey:@"missile_blast_meters"] floatValue];
        
        CLLocationCoordinate2D seoul = {Mlat,Mlong};
        MKCircle* circle = [MKCircle circleWithCenterCoordinate:seoul radius:radius];
        [myMap addOverlay:circle];
    }
Then i have the code to draw a circle.

Code:
-(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id)overlay{
    MKCircleView* circleView = [[[MKCircleView alloc] initWithOverlay:overlay] autorelease];
    circleView.strokeColor = [UIColor redColor];
    circleView.lineWidth = 1.0;
    circleView.fillColor = [UIColor colorWithRed:(255 / 255.0) green:(0 / 255.0) blue:(0 / 255.0) alpha: 0.1];
    return circleView;
}
Now the problem i am having is that every 3 seconds the circles are drawn, they are not being removed then redrawn and they are not being checked if duplicates.

I need some help please...

Alex
It sounds to me like you are adding all the overlays to your map every time you read your PHP data.

Are you saying that you want your overlays to be removed and re-added every 3 seconds, or are you adding new circles but keeping the old ones around?

If you are adding new ones, you need to keep track of the old count and only add the new ones on each pass.

If you want to remove all the circles and completely re-add them every 3 seconds, you might want to re-think. That will be a lot of work for the map to do on a repeating basis. Better to change the coordinate and radius of your existing circle objects, and only add new ones.

In any case, you need to figure out what you want to do, and code logic that manages the list of overlays to do what you want.

If you want to remove all your overlays and re-add them every 3 seconds, use code like this to remove the old ones:

Code:
[myMap removeOverlays: [myMap overlays]];
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 350
10 members and 340 guests
bignoggins, Chickenrig, firecall, givensur, iNet, linkmx, michaelhansen, Objective Zero, PlutoPrime, stanny
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,894
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:39 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0