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

  • Home
  • SEARCH
  • 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 7002291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:54:34+00:00 2026-05-27T20:54:34+00:00

I have a class that loads a map, get my current location, then does

  • 0

I have a class that loads a map, get my current location, then does a search on my database for companies in an area based on a zip code radius. I am doing a for loop to loop through each address, forward geocode, now I want to put a placemark and annotation for each location. How can I accomplish this. Here is my code:

- (void)locationUpdate:(CLLocation *)location {
locationLabel.text = [location description];
NSNumber *lat = [[NSString alloc] initWithFormat:@"%g", location.coordinate.latitude];
float latValue = [lat floatValue];
NSNumber *lng = [[NSString alloc] initWithFormat:@"%g", location.coordinate.longitude];
float lngValue = [lng floatValue];

mapView=[[MKMapView alloc] initWithFrame:self.view.bounds];
mapView.showsUserLocation=TRUE;
mapView.mapType=MKMapTypeStandard;
mapView.delegate=self;

/*Region and Zoom*/
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=0.2;
span.longitudeDelta=0.2;

CLLocationCoordinate2D location1=mapView.userLocation.coordinate;

location1.latitude=latValue;
location1.longitude=lngValue;
region.span=span;
region.center=location1;

/*Geocoder Stuff*/

geoCoder=[[MKReverseGeocoder alloc] initWithCoordinate:location1];
geoCoder.delegate=self;
[geoCoder start];

[mapView setRegion:region animated:TRUE];
[mapView regionThatFits:region];
[self.view insertSubview:mapView atIndex:0];
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geoCoder didFindPlacemark:(MKPlacemark *)placemark
{
NSDictionary *zipDic = [placemark addressDictionary];
NSString *zipCode = [zipDic objectForKey:@"ZIP"];
NSString *post = [NSString stringWithFormat:@"zip=%@", zipCode];
NSString *hostString = @"https://www.mysite.com/searchzip.php?";

// Append string and add percent escapes
hostString = [[hostString stringByAppendingString:post]    stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *hostURL = [NSURL URLWithString:hostString];
NSString *jsonString = [[NSString alloc] initWithContentsOfURL:hostURL];
self.zipArray = [jsonString JSONValue]; 
NSLog(@"%@", zipArray);
for (NSString *sZip in zipArray) {
     NSString *lblAddress = [sZip objectForKey:@"address"];
    NSString *hostStr = [[@"http://maps.google.com/maps/geo?q="   stringByAppendingString:lblAddress]stringByAppendingString:@"&key=ABQIAAAA1KqXKe5yJPkX6ii6Ud    K-0RSIvIZDM4KnjydqrehqKK56hFf_fxQc0uyCKoh-4i77-5B0Qfc8Gs223Q&sensor=false&output=json"];
    hostStr = [hostStr  stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    NSURL *hostURL = [NSURL URLWithString:hostStr];
    NSString *jsonString = [[NSString alloc] initWithContentsOfURL:hostURL];

    SBJSON *parser = [[SBJSON alloc] init];

    // parse the JSON string into an object - assuming json_string is a NSString of JSON data
    NSArray *object = [parser objectWithString:jsonString error:nil];

    NSArray *placemarks = [object objectForKey:@"Placemark"];
    NSDictionary *mark = [placemarks objectAtIndex:0];
    NSDictionary *point = [mark objectForKey:@"Point"];
    NSArray *coordinates = [point objectForKey:@"coordinates"];
    NSNumber *lat = (NSNumber*)[coordinates objectAtIndex:0];
    float latValue = [lat floatValue];
    NSNumber *lon = (NSNumber*)[coordinates objectAtIndex:1];
    float lonValue = [lon floatValue];

          //Here is where I would put placemarks and annotations
}

}
- (void)locationError:(NSError *)error {
locationLabel.text = [error description];
}

@end

I tried…

CLLocationCoordinate2D location = {latitude: latValue, longitude: lonValue};
    return location;

But obviously its wrong.
I tried creating a seperate MapAnnotation class to handle the annotations like so:

#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
#import "AgencyViewController.h"
@interface MapAnnotation : NSObject<MKAnnotation> {
CLLocationCoordinate2D coordinate;
NSString *subtitletext;
NSString *titletext;
}
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
@property (readwrite, retain) NSString *titletext;
@property (readwrite, retain) NSString *subtitletext;
-(id)initWithCoordinate:(CLLocationCoordinate2D) coordinate;
- (NSString *)subtitle;
- (NSString *)title;
-(void)setTitle:(NSString*)strTitle;
-(void)setSubTitle:(NSString*)strSubTitle;

and implement it like so:

CLLocationCoordinate2D newCoord = {latitude: latValue, longitude: lonValue};

    MapAnnotation *addAnnotation = [[MapAnnotation alloc] initWithCoordinate:newCoord];  
    [addAnnotation setTitle:@"The Pin Title"];  
    [addAnnotation setSubTitle:@"The pin subtitle goes here"];  

    [mapView addAnnotation:addAnnotation];  

And that didnt work either…

  • 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-27T20:54:34+00:00Added an answer on May 27, 2026 at 8:54 pm

    Figured it out, needed to add

    - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
    MKPinAnnotationView *pinView = (MKPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:@"Prospects"];
    if(pinView == nil) {
        pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Prospects"];
        pinView.pinColor = MKPinAnnotationColorGreen;
        pinView.animatesDrop = NO;
        pinView.canShowCallout = YES;
    } else {
        pinView.annotation = annotation;
    }
    return pinView;
    }
    

    Now I need to figure out how to change the color of my location pin.

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

Sidebar

Related Questions

I have an AS 3.0 class that loads a JSON file in using a
in AS3, I have an external class ImageLoader, that loads an image upon request.
I have a Java program that loads thirdparty class files (classes I did not
I have a class that map objects to objects, but unlike dictionary it maps
I have a map that is not displaying. The page loads all the controls
I have this class that have a function to load other classes and create
I have a class - XClass, that I want to load into an array
I have class that represents users. Users are divided into two groups with different
I have class method that returns a list of employees that I can iterate
I have a class that I want to use to store properties for another

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.