IPhone Google Location API V3在Google地图上显示自己创建的位置

时间:2014-07-10 06:31:38

标签: ios google-maps google-maps-api-3 google-places-api

如何在Google地图上显示自己创建的位置?

我已经注册了google location api,并在谷歌地方api v3的帮助下在谷歌上添加了新的位置。

我可以从谷歌获得成功回应,在谷歌上添加新的地方。

我尝试通过传递place_id和refance值来获取相同的位置,而不是我能够从谷歌的响应中获取位置信息,但当我在谷歌地图上搜索相同位置时使用"我创建的地名&#34 ;或者"放置地址"因为它无法向我展示我所创造的新地方api v3。

下面是我通过google place api v3添加新位置google的代码。

代码在谷歌上添加新地方,

NSString *str1 = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><PlaceAddRequest><location><lat>23.025651</lat><lng>72.507753</lng></location><accuracy>50</accuracy><name>Test Place on Gmap</name><phone_number>(91) 2339374 423000</phone_number><address>201 - Dev Arc Mall, Nr. ISKCON Bridge, S. G. Highway, Ahmedabad, Gujarat, India</address><type>food</type><website>http://www.testing.co.in/</website><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=AIzaSyDtsmfnmSKSgDGK4s5CJTNCV2GzZDtwoyE"]];
[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] ;
NSLog(@"returnstr: %@",returnstr);

通过执行此代码我可以在谷歌上创建位置,现在按类型获取相同的地址我无法得到这个地方作为响应,但我可以通过place_id或引用获得相同的细节。

currentCentre.latitude = 23.025651;
currentCentre.longitude = 72.507753;


// Fetch own created Location information
NSString *url = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/details/json?placeid=qgYvCi0wMDAwMDAzMzJjNjgxNjkwOjM5NWU5YjNhMTA1OjIwNmZhZjdmODcxNzlkZWM&key=AIzaSyDtsmfnmSKSgDGK4s5CJTNCV2GzZDtwoyE"];



NSURL *googleRequestURL = [NSURL URLWithString:[url        stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];


// Retrieve the results of the URL.
dispatch_async(kBgQueue, ^{
    NSData* data = [NSData dataWithContentsOfURL: googleRequestURL];
    [self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];
});

但我无法在Google地图上看到此地址或地点。

请帮助我。

由于

0 个答案:

没有答案