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 7658663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:13:52+00:00 2026-05-31T13:13:52+00:00

I’m currently working with the MKMapView and I’m trying to get data to appear

  • 0

I’m currently working with the MKMapView and I’m trying to get data to appear on screen. To accomplish this I’ve decided to right a small MapDataProvider that spits out an array of MKAnnotation objects – each containing a coordinate with random latitude and longitude values.

I’ve already made sure that my MKMapView is hooked up to my controller and the array of MKAnnotation objects are coming from my MapDataProvider correctly…but for some reason..when I try and specify coordinates in North America (ex. 48, -84)..nothing appears on the MKMapView.

After playing around I found out that any longitude value less than 0 gives me this issue.

I’ve tried verifying the coordinate value for each MKAnnotation object in my collection, but CLLocation2DIsValue() keeps returning false.

Question:

What range of values can I enter for latitude and longitude for a CLLocationCoordinate2D so my pins show up in North America?

To give a bit more context, here’s the method being invoked in the MapDataProvider:

+(NSArray *) getMockMapData{

NSMutableArray *tempMapData = [[NSMutableArray alloc] initWithCapacity:15];

for (int i=0; i< 15; i++) {

    double latitude = rand()%20 +50;
    double longitude = -107  + rand()%10;

    CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(latitude, longitude);

    if(CLLocationCoordinate2DIsValid(coord) == NO)
        continue;

    [tempMapData addObject:[MockMapData 
                            dataForValues:[@"Item " stringByAppendingString:[[NSNumber numberWithInt:i] description]]
                                 subTitle:[@"Item " stringByAppendingString:[[NSNumber numberWithInt:i]description]] 
                                coordinate:coord]];
    }
    return tempMapData;
}
  • 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-31T13:13:53+00:00Added an answer on May 31, 2026 at 1:13 pm

    Your original code was this:

    double latitude = arcrandom()%20 +50;
    double longitude = -107  + arcrandom()%10;
    

    (Actually, you probably had arc4random, not arcrandom.)

    The arc4random function returns an unsigned integer value.

    Subtracting an integer (-107) from that value resulted in an overflow which gave values like 4294967189. That would definitely be an invalid longitude.

    Instead of switching to rand (which the documentation says is a “bad random number generator”), use arc4random (which I believe is preferred) and force a floating point calculation by writing -107.0 instead of -107:

    double latitude = arc4random()%20 +50;
    double longitude = -107.0  + arc4random()%10;
    

    An unrelated point is that if CLLocationCoordinate2DIsValid says NO, you are just doing a return without sending back any value (which you need to according to the method declaration). Either do return tempMapData; or continue;.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has
I want use html5's new tag to play a wav file (currently only supported

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.