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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:35:24+00:00 2026-06-16T20:35:24+00:00

I implement Google Maps in my iPhone app. When I search for particular city

  • 0

I implement Google Maps in my iPhone app. When I search for particular city using a textfield Google Maps animates to that city for a moment and then moves back to my current location. I don’t know why its happing so please tell me what I need to do to get the desired location.

This is the code which I have implemented

-(IBAction)changeMapType:(id)sender{
    seg = (UISegmentedControl*)sender;
    if (seg.selectedSegmentIndex == 0) {
        mMapView.mapType = MKMapTypeStandard;
    }
    else if (seg.selectedSegmentIndex == 1) {
        mMapView.mapType = MKMapTypeSatellite;
    }

}


#pragma mark annotation callbacks

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
    NSLog(@"This is called");
    MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"customloc"];
    [annView setPinColor:MKPinAnnotationColorPurple];
    return annView;
}

#pragma mark location callbacks
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
    NSLog(@"location found... updating region");
    [self addPins:newLocation.coordinate.latitude lon:newLocation.coordinate.longitude];
}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
    NSLog(@"location not available");
}


#pragma mark geo functions

-(void)addPins:(float)lat lon:(float)lon{

    CLLocationCoordinate2D location;
    location.latitude = lat;
    location.longitude = lon;

    // forcus around you
    MKCoordinateRegion region;
    region.center=location;
    MKCoordinateSpan span;
    span.latitudeDelta=0.5f;
    span.longitudeDelta=0.5f;
    region.span=span;
    [mMapView setRegion:region animated:TRUE];


    float westLon = region.center.longitude - region.span.longitudeDelta;

    float southLat = region.center.latitude - region.span.latitudeDelta;


        // random fill the screen -> this should convert to database driven coordinates
        location.latitude=southLat + (region.span.latitudeDelta/50.0f)*(arc4random()%100);
        location.longitude=westLon + (region.span.longitudeDelta/50.0f)*(arc4random()%100);

        // add custom place mark
        CustomPlaceMark *placemark=[[CustomPlaceMark alloc] initWithCoordinate:location];
        placemark.title = @"Title Here";
        placemark.subtitle = @"Subtitle Here";
        [mMapView addAnnotation:placemark];
        [placemark release];


 }

    -(CLLocationCoordinate2D) getLocationFromAddress:(NSString*) address {
        // in case of error use api key like
        // http://maps.google.com/maps/geo?q=%@&output=csv&key=YourGoogleMapsAPIKey
        NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv",[address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]];
        NSArray *listItems = [locationString componentsSeparatedByString:@","];
        double latitude = 0.0;
        double longitude = 0.0;



        if([listItems count] >= 4 && [[listItems objectAtIndex:0] isEqualToString:@"200"]) {
            latitude = [[listItems objectAtIndex:2] doubleValue];
            longitude = [[listItems objectAtIndex:3] doubleValue];
        }
        else {
            //Show error
            NSLog(@"error:address not found");
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"ERROR" message:@"Address not found"
                                                           delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
            [alert show];
            [alert release];
        }

        CLLocationCoordinate2D location;
        location.latitude = latitude;
        location.longitude = longitude;

        return location;
    }

    #pragma mark search delegate
    - (IBAction)buttonclick:(id)sender
    {

        CLLocationCoordinate2D location2d = [self getLocationFromAddress:textfield.text];
        [self addPins:location2d.latitude lon:location2d.longitude];
        NSLog(@"location latitude  = %f",location2d.latitude);
        NSLog(@"location latitude  = %f",location2d.longitude);
    }
  • 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-06-16T20:35:25+00:00Added an answer on June 16, 2026 at 8:35 pm

    In the CLLocationManager delegate

    - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
    NSLog(@"location found... updating region");
    //[self addPins:newLocation.coordinate.latitude lon:newLocation.coordinate.longitude];
    }
    

    Comment the line [self addPins:newLocation.coordinate.latitude lon:newLocation.coordinate.longitude]; as it is zooming to your current location.

    or in your -(void)addPins:(float)lat lon:(float)lon function execute the following line for only once with the help of a Bool

    if(!executeOnce) // executeOnce is a BOOL
    {
    
    MKCoordinateRegion region;
    region.center=location;
    MKCoordinateSpan span;
    span.latitudeDelta=0.5f;
    span.longitudeDelta=0.5f;
    region.span=span;
    [mMapView setRegion:region animated:TRUE];
    
    executeOnce = YES;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing an android app that will use Google Maps but to implement
It seems that the search in the Google Maps app is location aware .
Good Morning, Im using the Google Maps V3 to implement a project. In my
I want to allow users to add places to Google Maps using my app.
I'm using GMaps.js to implement some Google Maps functionality on my website. This library
How to implement google maps search by address in Android?
I need to implement directions using Google maps inside my GWT web application. Currently
Trying to implement google C2DM service. registrationIntent.putExtra(app, PendingIntent.getBroadcast(context,0,new Intent(), 0)); registrationIntent.putExtra(sender,example@gmail.com); context.startService(registrationIntent); Almost every
I am trying to use django-social-auth to implement google openid login into my app,
Possible Duplicate: How to make half curl animation in iPhone like the maps app

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.