Xcode KML Viewer only displays about 5miles on the map

I have a KML file with over 2000 locations, but when I use this, it takes over 5 minutes to load all the locations. now my question is whether it is possible to download the map only in locations 5 miles from the local location and add a button for the user to click on when needed to use all locations.

Please help me, I am a hobby programmer and will not find a solution, thanks for in advance

+3


source to share


1 answer


You should create CLLocation

objects for currentLocation

and a placemarkLocation

specific KML label and then you can use distanceFromLocation

to see how much (in meters) they are. And given that there are 1,609.34 meters per mile, five miles is therefore 8,046.72 meters:

CLLocation *placemarkLocation = [[CLLocation alloc] initWithLatitude:latitude
                                                           longitude:longitude];

if ([placemarkLocation distanceFromLocation:currentLocation] < 8046.72)
{
    // add placemark to map
}
else
{
    // don't
}

      




I have two observations:

  • You said the download process takes 5 minutes. I find it very suspicious and surprising if you have something else going on. I just giggled and grinned, added 2000 annotations to the annotation, and it took a few seconds, not a few minutes. I would suggest that you make a diagnosis to determine the source of the delay, because there is no point in optimizing the map generation if the problem is with XML parsing or something. Do some diagnostic work to determine what is actually the source of your delay.

    If, for example, the problem is that you are downloading a huge KML file over the Internet, which is measured in tens or hundreds of megabytes, any optimization MKMapView

    will have little impact on overall performance. This is just a random example, but make sure you really understand the source of the problem.

  • Adding 2000 annotations to mine MKMapView

    on the iPhone 5 took a few seconds, it's clearly not a big UX (both in terms of a few seconds of latency and the idea of ​​having two thousand annotations that you obviously can't visually distinguish on the iPhone screen). You suggested that you grab tags that are within 5 miles and that you give the user an alternative to select all of them. Perhaps I suggest a different approach:

    Instead of coding this logic "five miles or all", I suggest you look at region

    either visibleMapRect

    for MKMapView

    and show the annotations that fall into that region, or MKMapRect

    , better yet, just show the 100 annotations that fall into the region. And if you hooked this up regionDidChangeAnimated

    , it would get new annotations as needed.

+1


source







All Articles