Search code examples
iosobjective-ciphonegoogle-maps-sdk-ios

Objective C Google maps


Below is my code for getting latitude and longitude of the location but whenever it is executed it returns this:

You have exceeded your daily request quota for this API. We recommend registering for a key at the Google Developers Console.

I have my API key but I don't know where to put it.

GoogleMapsViewController *obj=[self.storyboard instantiateViewControllerWithIdentifier:@"googlemap"];
NSString *givensource=self.sourcetxt.text;
NSString *givendest=self.destinationtxt.text;
NSString *sendtourl=[NSString stringWithFormat:@"https://maps.google.com/maps/api/geocode/json?sensor=false&address=%@",givensource];

NSURL *url = [NSURL URLWithString:sendtourl];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[NSURLConnection
    sendAsynchronousRequest:request
    queue:[NSOperationQueue mainQueue]
    completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
    if (data.length > 0 && connectionError == nil) {
        NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:NULL];
        NSLog(@"ABC");
    }
}];

Solution

  • For that you need to register your application and get the API key. You need to use this API key with each request by appending it with the URL:

    NSString *sendtourl = [NSString stringWithFormat:@"https://maps.google.com/maps/api/geocode/json?sensor=false&address=%@?key=your key", givensource];