我可以使用Google Places API搜索地點。 如何使用Google Places API添加我的地點?我看過文檔 ,但無法弄清楚。 http://code.google.com/apis/maps/documentation/places/#PlaceSearchRequests 任何人都可以幫助我。如何在iPhone App中添加Google Places API的地點
回答
我在的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]);
}
使用下面的示例添加一個地方。
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"
}
嗨raj plz讀我的問題我能夠搜索的地方,但現在我想添加的地方。如果你知道的東西比請與我分享。 –
嗨suraj,看到這個新的答案。它會幫助你。 –
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);
使用上面的代碼你一定w'll添加新的地方,谷歌API ....只是改變你的緯度,經度,名稱&你的API在上面的代碼中的鍵值..
嗨,我用這個代碼,並代替了我自己的所有值,並在響應中收到確定。問題是這個地方還沒有顯示在我的地圖上。我使用相同的API密鑰和附近的搜索。 – ferris
- 1. Google Places API:添加新地點:Java/Groovy
- 2. Google Places API地點描述
- 3. 向Google Places添加新地點
- 4. 通過API向Google Places添加新地點的PHP代碼
- 5. 如何添加Google Places API結果以覆蓋地圖?
- 6. 如何唯一標識Google Places API中的某個地點
- 7. Google Places API - Web App的方法
- 8. Google Places API - 法國地區
- 9. 無法添加Google Places API密鑰
- 10. Google Places API wnd Windows 8 Metro Style App
- 11. 看不到我添加的地方 - Google Places API
- 12. 如何使用Google Places API搜索特定類型的地點?
- 13. 如何使用Google Places API獲取特定類型的地點?
- 14. Google Places在添加地點時POST「INVALID_REQUEST」響應
- 15. Google places Api Key
- 16. 如何在Android中實現Google Places API?
- 17. 通過Google Place API API服務添加地點
- 18. Google API for Restaurants Places
- 19. Google Places - 當前地點拋出:在Places API庫中發生內部錯誤
- 20. Google Places Api Android
- 21. Google Places API Warning
- 22. Google Places API - 使用複選框中的多個地點類型
- 23. 在catch-22時如何加載Google的Places API和Map API?
- 24. Google Places JavaScript API v3,如何將我的API密鑰添加到請求中?
- 25. Google Places API - android
- 26. Google Places API subway_station ,?
- 27. Google Places API cors
- 28. Google Places API
- 29. 如何使用Google Places API滾動地圖時更新附近的地點?
- 30. Google Places API的顯示歸屬地
嘿嗨,謝謝,但我的問題是我如何添加新的地方到谷歌地方API –
你想通過谷歌API的mapview多個地方? –
沒有yaar我想添加我自己的地方。 –