简体   繁体   中英

Some pins sometimes don't show up on MKMapView… WHY?

So I have the following code, that splits up the street,town,state,country,zip and makes an AddressAnnotation, a class I have extended from annotation.

Sometimes all of the pins show up on the map and sometimes it cannot find some of the places, although it is a collection of the exact same addresses every time. Is there any reason why Google maps can find a place sometimes but not all the time?

Is it something in my code?

Thanks, R

for (int i=0; i < [places count]-1; ++i) {

    NSArray *arrayPlace = [[places objectAtIndex:i] componentsSeparatedByString:@"***"];

    AddressAnnotation *addAnnotation = [[AddressAnnotation alloc] initWithCoordinate:
                                        [self getLocationFromAddressString:
                                         [NSString stringWithFormat:
                                          @"%@ %@ %@ %@ %@ %@",
                                          [arrayPlace objectAtIndex:3],
                                          [arrayPlace objectAtIndex:4],
                                          [arrayPlace objectAtIndex:5],
                                          [arrayPlace objectAtIndex:6],
                                          [arrayPlace objectAtIndex:7],
                                          [arrayPlace objectAtIndex:8]]]];




    [addAnnotation setWebsite:[arrayPlace objectAtIndex:2]];
    [addAnnotation setTitle:[arrayPlace objectAtIndex:0]];
    [addAnnotation setSubtitle:[arrayPlace objectAtIndex:1]];


    [mapView addAnnotation:addAnnotation];
}

Shouldn't it be in the first line something like this?

for (int i=0; i < [places count]; i++) {

or better just:

for (NSArray *arrayPlace in places) {

Try logging the address strings you are generating. If they are always the same then look into getLocationFromAddressString and see if the coordinates it is returning are always the same. If not then that function has the problem. I've looked around for that function but Google just keeps bringing me back to StackOverflow. Is it your own function or have you used the one from this question? MKMapView with address

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM