1

I'm new to iOS and working on Google Map SDK and able to show the map on the view but now

  1. I want to add a UITextField and enter the location over there
  2. On buttons click that location should be shown in the map

So please kindly help me out.

Amar
  • 13,202
  • 7
  • 53
  • 71
sahil dhiman
  • 91
  • 1
  • 1
  • 7

1 Answers1

2

I would suggest you to add buttons on the UINavigationBar or by placing a UIToolBar on the top of the map view and then by clicking on it show a UIAlertView with textfield that takes in the input and after the alert's ok is pressed take the location entered and do your stuff. Don't add buttons on the map,it would bring down the usability factor.

If you have a navigation bar already, try this

UIBarButtonItem *locationButton = [[UIBarButtonItem alloc] initWithTitle:@"location" style:UIBarButtonItemStyleBordered target:self action:@selector(showAlertWithTextField)];
self.navigationItem.rightBarButtonItem=locationButton;


-(void)showAlertWithTextField{
    UIAlertView* dialog = [[UIAlertView alloc] initWithTitle:@"Enter Location" message:@"" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Add", nil];    
    [dialog setAlertViewStyle:UIAlertViewStylePlainTextInput];
    [dialog show];
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 1)
        NSLog(@"%@",[[alertView textFieldAtIndex:0]text]);
}
Satheesh
  • 10,998
  • 6
  • 50
  • 93
  • k i got ur point bro, can u please give me any sample of how the place entered in the textfeild is searched in the google-map view. – sahil dhiman Oct 21 '13 at 09:34
  • one more question brother, can u tell me how can we search the place which is entered in the text feild, so that we can view it on the map.?? – sahil dhiman Oct 21 '13 at 10:58
  • You would have a tick button and the up arrow button at the start of my answer towards the right. You cannot search the mapview for places, mapview understands only latitude and longitude values so it would be better you search for a place using google places api get a set of latitudes and longitudes to pin point on the map view. – Satheesh Oct 21 '13 at 11:13
  • http://stackoverflow.com/questions/15076738/google-maps-ios-sdk-search-for-places gives everything you need. – Satheesh Oct 21 '13 at 11:16
  • the link u send me helped me in understanding the thing but how can i impliment it... – sahil dhiman Oct 21 '13 at 11:25
  • Ok here is a tutorial http://www.raywenderlich.com/13160/using-the-google-places-api-with-mapkit , you can't get the real thing you want but you gotta tweak this a bit. You also have sample code at the end of the article. – Satheesh Oct 21 '13 at 11:27