Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google API gives error when location entering in Danish language setting in iPhone Application

I am using a Google API to finding latitude longitude from Address location. And its working fine in English language settings. But when select Danish setting in Internationalization then it gives a server error from "Google". As I think there may be required to do localization in app but how?

When language selected as Danish and response gives by Google API

like image 624
Arpit Kulsreshtha Avatar asked Mar 21 '13 13:03

Arpit Kulsreshtha


People also ask

How do I change the language of the Google App?

You can choose the language you use for Google products and search results. To change the language the Google app uses, change your phone's language setting. When you change this setting, it will change the language of all apps on your phone.

What is a location and Context API?

The location and context APIs harness the sensors and signals of mobile devices to provide awareness of user actions and their environment, enabling delightful and engaging experiences that simplify user interactions, provide assistance, and help users to better understand themselves.

What languages are supported by the translation API?

Language support. The Translation API's recognition engine supports a wide variety of languages for the Phrase-Based Machine Translation (PBMT) and Neural Machine Translation (NMT) models. These languages are specified within a recognition request using language code parameters as noted on this page.

Why is Google Maps API not authorized to use my API?

This API Project Is Not Authorized To Use This API You’ll get this server error when you try to access one of the Google Maps Libraries (such as Places API ) without enabling it on the Google Cloud Console. The API service will return a response JSON object in which you can find the error under the error_message property.


2 Answers

Muhammad is giving the answer above, but I'll take the opportunity to explain what (I think) the issue is as well, as I had this issue in live production code a few weeks ago.

NSURL is flat out bad with unescaped strings with "special" content (e.g. UTF). First thing I'd do is check if the NSURL you get back is nil.

The way to do NSURL strings is to use stringByAddingPercentEscapesUsingEncoding before passing the string in.

This simple example demonstrates this:

NSString *string = @"http://test.com/teståäötest";

NSLog(@"url with string! %@", [NSURL URLWithString:string]);
NSLog(@"url with escaped string! %@", [NSURL URLWithString:
  [string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]);

with output

url with string! (null)
url with escaped string! http://test.com/test%C3%A5%C3%A4%C3%B6test
like image 110
Kalle Avatar answered Sep 20 '22 09:09

Kalle


I am not sure about AFNetworking, but I would do it as below with Apple's NSURL.

Assume your URL is a string named "googlapiurl", your NSURL should be initiated as:

[NSURL URLWithString:[googlapiurl stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]];

Hope it helps.

like image 28
MuhammadBassio Avatar answered Sep 19 '22 09:09

MuhammadBassio