Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
来自iPhone/sim的Google geocode API上的状态代码0,但在web上运行良好(非英语字符)_Iphone_Geocoding_Google Api_Reverse Geocoding - Fatal编程技术网

来自iPhone/sim的Google geocode API上的状态代码0,但在web上运行良好(非英语字符)

来自iPhone/sim的Google geocode API上的状态代码0,但在web上运行良好(非英语字符),iphone,geocoding,google-api,reverse-geocoding,Iphone,Geocoding,Google Api,Reverse Geocoding,Try:=厄尔博蒂安,匈牙利&传感器=true 在iPhone4和模拟器上 -(void)requestFailed:(ASIHTTPRequest *)request { NSLog(@"geocode fail code: %d",[request responseStatusCode]); NSLog(@"geocoding failed: %@",[request responseString]); } 2011-06-01 11:36:27.343 app[1174:30

Try:=厄尔博蒂安,匈牙利&传感器=true

在iPhone4和模拟器上

 -(void)requestFailed:(ASIHTTPRequest *)request {
   NSLog(@"geocode fail code: %d",[request responseStatusCode]);
   NSLog(@"geocoding failed: %@",[request responseString]);
}
2011-06-01 11:36:27.343 app[1174:307] geocode fail code: 0
2011-06-01 11:36:27.345 app[1174:307] geocoding failed: (null)
在浏览器中,我得到:

   "results" : [
    {
    "address_components" : [
        {
           "long_name" : "Őrbottyán",
           "short_name" : "Őrbottyán",
           "types" : [ "locality", "political" ]
        },
        {
           "long_name" : "Pest",
           "short_name" : "Pest",
           "types" : [ "administrative_area_level_1", "political" ]
        },
        {
           "long_name" : "Hungary",
           "short_name" : "HU",
           "types" : [ "country", "political" ]
        }
     ],
     "formatted_address" : "Őrbottyán, Hungary",
     "geometry" : {
        "bounds" : {
           "northeast" : {
              "lat" : 47.7138950,
              "lng" : 19.34353090
           },
           "southwest" : {
              "lat" : 47.63339999999999,
              "lng" : 19.2051070
           }
        },
        "location" : {
           "lat" : 47.6846190,
           "lng" : 19.2883260
        },
        "location_type" : "APPROXIMATE",
        "viewport" : {
           "northeast" : {
              "lat" : 47.7138950,
              "lng" : 19.34353090
           },
           "southwest" : {
              "lat" : 47.63339999999999,
              "lng" : 19.2051070
           }
        }
     },
     "types" : [ "locality", "political" ]
  }
],, “状态”:“确定” }


其他包含标准英文字符的请求也能正常工作并在设备上正确返回。

在代码中的某个点,您可能正在使用
NSURL
类,并且:

NSURL类将无法创建 如果路径为 通过的路径不是格式良好的路径 必须符合RFC 2396的要求。例子 无法成功的案例包括: 包含空格字符的字符串 和高位字符。应该 创建NSURL对象失败时 创建方法返回nil,您可以 必须准备好应付

在将字符串传递到
NSURL
之前,需要使用
[NSString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
将“Őrbottyán”中的高位字符转换为百分比转义。当您将不兼容的字符串放入URL字段时,现代浏览器将默默地为您进行此转换,但在代码中您必须显式地进行转换


编辑将quantumpotato的发现包括在下面:如果“Orbottyan”被转换为“Orbottyan”(一种“有损”转换为ASCII编码),谷歌地图将做正确的事情,并且这种转换可以通过
NSData
进行往返:

NSData *data = [urlString dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *dataString = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
NSURL *url = [NSURL URLWithString:dataString];
[dataString release];
我怀疑“有损转换为ASCII”可能不适用于所有网站,但它已经过谷歌地图的测试和验证,所以你就有了它。:-)

当我将请求更改为“Orbottyan,Hungary”时,它就起作用了。这就做到了:“NSData*data=[urlString dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];NSString*dataString=[[NSString alloc]initWithData:dataencoding:NSASCIIStringEncoding];NSURL*url=[nsurlwithstring:dataString];[dataString release];”编辑您的答案以包含“^”,我会将其标记为正确。谢谢