The app uses the Geocoder object. It works fine on my stock Froyo Nexus One. But then I run the exact same app on a different device (an Advent Vega 10" tablet also running Froyo) and I get this exception: Service not Available. The method I'm using is getFromLocationName(), I'm building against the Android 1.6 Google API.
I'm aware of an issue where this exception is thrown on the emulator, but I suspect this is different. Why would it be thrown on one device running Froyo but not another?
The app is a location app, and as the tablet has no GPS or mobile network, in a scenario where the Wi-Fi connection doesn't provide a location, the user must manually specify it, so not being able to use the Geocoder object is bad news.
I could add a way for the user to select the location on a map, but it's not ideal. Possibly I could use the Google Maps API directly, but I'm keen to understand the nature of the issue first as would be nice to have an easier solution.
Hopefully in a future release Android will include an OS-level "default location" for non-Geocoder devices, so location-aware apps work out of the box on devices like Google TV.
I asked Google's Reto Meier to confirm my theory was correct and he said "Correct. The Geocoder is part of the Google API add-on that isn't part of the AOSP."
So any device that doesn't come with the Play Store, GMail apps etc… will also be missing the Geocoder back-end.
There seems to be another possible workaround for this problem, which is unfortunately marked as a duplicate question, and therefore might be missed. Essentially, a reboot of the device clears up the problem. Note I called it a "workaround" and not a "solution". :(
For those who searching alternative, Hopefully, my answer in another post is useful.
You can use Google Geocoding API when caught error in geocoding.
For more code => Get current location using json
Some devices do not have suport for Geocoder, so what you need to do is create your own geocoder.
Basicaly you need create a async task to request google for the address and treat the json response.
Using aquery, i do something like this:
public void asyncJson(String address){
address = address.replace(" ", "+");
String url = "http://maps.googleapis.com/maps/api/geocode/json?address="+ address +"&sensor=true";
aq.ajax(url, JSONObject.class, new AjaxCallback<JSONObject>() {
#Override
public void callback(String url, JSONObject json, AjaxStatus status) {
if(json != null){
//here you work with the response json
JSONArray results = json.getJSONArray("results");
Toast.makeText(context, results.getJSONObject(1).getString("formatted_address"));
}else{
//ajax error, show error code
Toast.makeText(aq.getContext(), "Error:" + status.getCode(), Toast.LENGTH_LONG).show();
}
}
});
}
After wasting several hours, I got a simplest solution.
I Just restarted my device, and it started working.
It seems, the problem is due to some OS level caching problem. Hope it will also work for your..
I had the same issue. I used the following function.
Note:
Use context of your Activity and don't use getApplicationContext() to the following function
public static Address getLocalityFrmGeoCoder(Context context, Location mLocation) {
try {
if(mLocation!=null){
Geocoder gCoder = new Geocoder(context, Locale.getDefault());
List<Address> address = gCoder.getFromLocation(mLocation.getLatitude(), mLocation.getLongitude(), 1);
if (address.size() > 0) {
return address.get(0);
}
}
} catch (Exception e) {
Log.d("GEOCODER", "GEOCODER EXCEPTION");
e.printStackTrace();
}
return null;
}
Related
If someone could help me. Is using geocoder free for android, currently i'm only using google maps. I see that it says that its only 2500 requests per day. Or is this only for web and something entirely different from mobile?
I am using the following code to get a zip code with a latitude and longitude.
final Geocoder geocoder = new Geocoder(getActivity());
try {
List<Address> addresses = geocoder.getFromLocation(mLocationClient.getLatitudeCoordinate(), mLocationClient.getLongitudeCordinate(),5);
for (Address address: addresses){
if(address.getLocality()!=null && address.getPostalCode()!=null){
Log.v("Zip code", " " + address.getPostalCode());
}
}
} catch (IOException e) {
e.printStackTrace();
}
https://developers.google.com/maps/pricing-and-plans/#details
Just trying to make sure. I'm super confused on this and some clarification could help :) Thanks
The Geocoder use is totally free.
The link you wrote is related to Google Maps and Google Places API, not the Geocoding API. This is the correct link:
https://developers.google.com/maps/documentation/geocoding/usage-limits
Anyway you are not using the Geocoding API with this code, you just using the Geocoder of Android.
This is the documentation to use the Geocoding API if you want:
https://developers.google.com/maps/documentation/geocoding/intro
The Geocoding API works better than Geocoder normally but has usage limits and the implementation is bigger.
Not any more. Google just decided to 10x their price for geocoding https://cloud.google.com/maps-platform/pricing/sheet/
I've just delved into the world of Global Positioning System (GPS) and found the following interesting facts:
1) The Android class android.location.Geocoder always returns null when getting address via reverse geocoding. The code I used is:
Geocoder mGeocoder = new Geocoder(context, locale);
List<Address> addresses = mGeocoder.getFromLocation(latitude, longitude, 1);
if (!addresses.isEmpty()) {
// do something.
} else {
// Display a message regarding no address available.
}
The reason is stated here:
The Geocoder class requires a backend service that is not included in
the core android framework.
So, essentially I would either have to provide offline geolocation data myself for reverse geocoding, or my Android app will have to connect to the Internet and look up geolocation data from Google (via http://maps.googleapis.com/maps/api/geocode/json?latlng= for example). Or use alternative geolocation providers like OpenStreetMap, etc.
2) Android apps like Google Maps requires an Internet connection; while offline provider like TomTom bundled offline geolocation data together with their app so an Internet connection is not needed.
Beside the stated facts above, is there another alternative for retrieving geolocation address without using offline reverse geographic data or using an Internet connection?
If you have some experience with geocoding and reverse geocoding in Android, then please post your thoughts.
Thanks.
There is at least one way for each.
For reverse-geocoding, you let the user mark the geolocation of the address himself using gps.
For geocoding, you let the user hunt down a set of coordinates and then you have him read the street name and the address he finds himself at.
There are few offline libraries available to reverse Geocode offilne. Suggest you to go through these libraries.Personally i have not used these libraries.Let me know if you still face any problems.
https://developers.arcgis.com/android/
Sample code for link:
https://github.com/Esri/arcgis-runtime-samples-android/tree/master
I'm trying to make games API work, with reference to https://github.com/playgameservices/android-samples/blob/master/BaseGameUtils/src/com/google/example/games/basegameutils/BaseGameActivity.java as sample code.
Mine is quite similar, basically I'm trying to connect a game client and receive a negative answer. When trying to manage it with startResolutionForResult() this is what I got:
E/Volley(15638): [1492] il.a: Unexpected response code 403 for https://www.googleapis.com/games/v1/players/112370814111712506xxx
E/Volley(15638): [1492] il.a: Unexpected response code 403 for https://www.googleapis.com/games/v1/players/112370814111712506xxx
E/SignInIntentService(15638): Access Not Configured
[...]
E/LoadSelfFragment(15748): Unable to sign in - application does not have a registered client ID
The last message, "application does not have a registered client ID" made me think to this question...But I don't think my issue is related to app id / client ID as I got it working with same API keys on another machine. I'm pretty sure of SHA1 correctness, too, derived from current machine's debug.keystore.
The issue seems to be related to test address I'm using, the strange thing is that I don't receive always the same reply: using same keys and settings, I sometimes got:
E/SignInIntentService(15638): Access Not Configured
or even:
E/SignInIntentService(15638): Unable to load player
I'm using startResolutionForResult() inside OnConnectionFailedListener, it's showing the log-in screen briefly, but then it crashes with reported errors.
Another strange thing is that onActivityResult() is called, and result code is 10004
A last thing I can't understand is why, after an unsuccessful sign-in, the method onConnectionFailed() is called over and over, looping my app. Relevant code is:
public void initClient() {
GamesClient.Builder gcBuilder = new GamesClient.Builder(this, cb, cf);
gcBuilder.setGravityForPopups(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
//gcBuilder.setScopes(mScopes);
mGamelient = gcBuilder.create();
mSchiacciameleView.setGameClient(gcBuilder.create());
}
OnConnectionFailedListener cf = new OnConnectionFailedListener() {
public void onConnectionFailed(ConnectionResult arg0) {
Log.e("Verme", "CONN FAIL:" + arg0.getErrorCode());
if (arg0.hasResolution()){
PendingIntent pendingIntent = arg0.getResolution();
//startResolutionForResult(SchiacciaMeleGame.this, 66);
try {
arg0.startResolutionForResult(me, ConnectionResult.SIGN_IN_REQUIRED) ;
} catch (SendIntentException e) {
Log.e("Verme", "Err in resolution", e);
}
}else{
Log.e("Verme", "NO RESOLUTION");
}
}
};
I've been messing with these libraries for two days. Frankly, I don't like the way Google is managing this; documentation is still incomplete and run-time behaviour seems a bit inconsistent (the exact same code is working on another machine, SHA1 is correct on both). Maybe it's my fault?
Thank you for replies
In Step 3. Generate an OAuth 2.0 client ID it specifically gives a warning as follows:
Warning: Do not open the Google APIs Console directly and manually
add your Client IDs on that page. Doing so might cause errors when
you send requests to the game services.
So my experience was that you need to follow the guide religiously: Setting Up Google Play Game Services with the Google Play Developer Console
I have a problem with receiving translations from Google via translate API. Does somebody know what is wrong? Thanks!
Note:
It has worked fine for some time but maybe 5 months ago it stopped to work.
#Override
public void onClick(View v) {
GoogleAPI.setHttpReferrer("http://code.google.com/p/google-api-translate-java/");
GoogleAPI.setKey("xxx");
try {
tv_answer.setText(Translate.DEFAULT.execute(tv_source.getText().toString(), Language.CZECH, Language.ENGLISH));
} catch (GoogleAPIException e) {
e.printStackTrace();
}
}
Received error:
com.google.api.GoogleAPIException: java.lang.Exception: [google-api-translate-java] Error retrieving translation.
This problem only appears on android when using this api client. I believe this is because this api client is old and/or poorly written.
You can attempt to get the source code from here and fix the problem yourself, or just use the api directly from Java using GET with HttpURLConnection and them parse the JSON.
Google Translate API is a paid service.
Note:
(https://developers.google.com/translate/v2/getting_started)
Problem with the new App engine connected android application projects for the google eclipse plugin? This is the "Big Daddy" sample shown at goolge i/o 2011. My sample project compiles and the android app appears to work fine and registers with the server. However when I send a message from the server I get the following: Having issue with sample project. Android appears to work fine and registers with the server and the c2dm server, however I cannot send a message.
Also of note on the server is a c2dmconfig datastore object. It has fields for authToken and c2dmUrl. The authToken has a token, however the c2dmUrl is NULL. I suspect this is where my problem lies, but not sure how to fix it.
Thanks Patrick
I found this question by wondering the same thing, if the c2dmUrl being null is a problem. It would seem that this is not an issue though. If you look at the C2DMConfig (the entity that you are referencing), there is a function called "getC2DMUrl". Here it is:
public String getC2DMUrl() {
if (c2dmUrl == null) {
return DATAMESSAGING_SEND_ENDPOINT;
} else {
return c2dmUrl;
}
So null is a supported value for this. If a specific URL isn't specified, it simply returns it to the default.