Как добавить места в Google Places API в приложении для iPhone - PullRequest
1 голос
/ 24 января 2012

Я могу искать места, используя Google Places API. Как я могу добавить свои места, используя Google Places API. Я видел документацию но не в состоянии понять это. http://code.google.com/apis/maps/documentation/places/#PlaceSearchRequests Кто-нибудь может мне помочь.

Ответы [ 3 ]

0 голосов
/ 24 января 2012

Используйте следующий пример для добавления места.

    POST https://maps.googleapis.com/maps/api/place/add/json?sensor=true_or_false&key=api_key 
    HTTP/1.1
    Host: maps.googleapis.com

    {
      "location": {
        "lat": -33.8669710,
        "lng": 151.1958750
      },
      "accuracy": 50,
      "name": "Google Shoes!",
      "types": ["shoe_store"],
      "language": "en-AU"
    }
0 голосов
/ 19 марта 2013
  NSString *str1 = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><PlaceAddRequest><location><lat>24.003372</lat><lng>75.770232</lng></location><accuracy>50</accuracy><name>test pet house</name><type>pet_store</type><language>en-US</language></PlaceAddRequest>"];
  NSLog(@"str1=====%@",str1);

NSString *str2 = [str1 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSData *requestdata = [NSData dataWithBytes:[str2 UTF8String] length:[str2 length]];
NSString *postLength = [NSString stringWithFormat:@"%d", [requestdata length]];


NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://maps.googleapis.com/maps/api/place/add/xml?sensor=false&key=your own api key"]];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];

[request setHTTPMethod:@"POST"];
[request setHTTPBody:[NSData dataWithBytes:[str1 UTF8String] length:[str1 length]]];

//NSURLConnection *placesConn =[[NSURLConnection alloc] initWithRequest:request delegate:self];
NSData *returndata = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnstr = [[[NSString alloc] initWithData:returndata encoding:NSUTF8StringEncoding] autorelease];
NSLog(@"returnstr: %@",returnstr);

Используйте код выше. Вы наверняка добавите новое место в Google API .... просто измените значения lat, long, name и api key в приведенном выше коде.

0 голосов
/ 24 января 2012

в моем приложении я печатаю местоположение в UIsearchbar и после этого вызываю следующий метод

-(void)getLocation
{
      NSString *urlString;
        if(locationFinder.text!=nil)
        {
            urlString = [[NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv", [locationFinder.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]retain];
        }


                NSLog(@"url:%@",urlString);

            NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]];
            NSArray *listItems = [locationString componentsSeparatedByString:@","];


            if([listItems count] >= 4 && [[listItems objectAtIndex:0] isEqualToString:@"200"]) 
            {
                latitude = [[listItems objectAtIndex:2] doubleValue];
                longitude = [[listItems objectAtIndex:3] doubleValue];
            }

            NSLog(@"latitude: %f longitude:%f",latitude,longitude);

            urlString=[NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/search/json?location=%f,%f&radius=%d&types=%@&sensor=true&key=AIzaSyBbUuE-DprCN-CME1SgcNxyeuDdRrBgkyk",latitude,longitude,mRadius,mTypes];

        NSLog(@"url: %@",urlString);
        NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:180.0];
        id urlRequest = [[NSURLConnection alloc] initWithRequest:request delegate:self];
        if(urlRequest)
        {
                responseData=[[NSMutableData data]retain];
                NSLog(@"hiiii i m data");

          }
    }

и реализации некоторого другого метода делегата и анализа данных через jSON

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    [responseData setLength:0];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    //NSLog(@"DATA:%@",data);
    [responseData appendData:data];
    //NSLog(@"%@",responseData);
     //[responseData release];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    NSLog(@"connection failed:%@",[error description]);
    //done.enabled = YES;
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    [connection release];

    //NSLog(@"response data:%@",responseData);
    NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
    //NSLog(@"response:%@",responseString);
     //[responseData release];
    NSDictionary *locationData = [responseString JSONValue];
    NSLog(@"ALLKEYS:%@",[locationData allKeys]);
          self.responseDataDict=[locationData objectForKey:@"results"];
          NSLog(@"locationdata allkeys:%@",[locationData allKeys]);
        NSLog(@"name:%d",[responseDataDict count]);



}
...