android-reverse geocoding-Google Map API (geocoding) - android

I'm developing android app where I use google reverse geocoding API webservice in the user side, for the user to read his address in text format.
HttpGet httpGet = new HttpGet(
"http://maps.googleapis.com/maps/api/geocode/json?latlng="
+ lat + "," + lng + "&sensor=true");
I have the following three questions:
1-Do I have to use a map in my app?, as I'm only displaying the location in text to User and I don't want a map in my app?
https://developers.google.com/maps/terms#section_10_1
"(h) No Use of Content without a Google Map. You must not use or display the Content without a corresponding Google map, unless you are explicitly permitted to do so in the Maps APIs Documentation"
2-is it a must that I include API key at app side part of calling the webservice?
3-am I expected to establish enterprise agreement with Google, and get client_ID and include it in the request sent by the end user?
https://developers.google.com/maps/terms#section_9_1

To answer the questions:
1) I think you can use this without using the maps, for, in the API doc it said:
The Google Geocoding API provides a direct way to access a these services via an HTTP request.
https://developers.google.com/maps/documentation/geocoding/#Geocoding
2) You need an API key for using the service, even it works without using one (not recommended). Refer to this section for more information.
All Maps API applications* should load the Maps API using an API key. Using an API key enables you to monitor your application's Maps API usage, and ensures that Google can contact you about your application if necessary.
https://developers.google.com/maps/documentation/javascript/tutorial#api_key
3) for client_id, I think you don't need to unless you have to..
https://developers.google.com/maps/documentation/business/

Related

Not able to fetch polyline polypoints because of restricted Google Maps API Key: Flutter

I am using a Google Maps API Key which permits calls through SDK only. I want to display polyline between source and destination location but I get the following message with my code-
This IP, site or mobile application is not authorized to use this API key. Request received from (IP ADDRESS), with empty referer status:REQUEST_DENIED points:[]
I am using the most used package: https://pub.dev/packages/flutter_polyline_points
But, I cannot get the poly points using the provided method-
_getPolyline() async {
PolylineResult result = await polylinePoints.getRouteBetweenCoordinates(
googleAPiKey,
PointLatLng(_originLatitude, _originLongitude),
PointLatLng(_destLatitude, _destLongitude),
travelMode: TravelMode.driving,
wayPoints: [PolylineWayPoint(location: "Sabo, Yaba Lagos Nigeria")]);
if (result.points.isNotEmpty) {
result.points.forEach((PointLatLng point) {
polylineCoordinates.add(LatLng(point.latitude, point.longitude));
});
}
_addPolyLine();
}
The method polylinePoints.getRouteBetweenCoordinates() uses a URL to fetch responses, but this is not permitted for restricted API Keys, which allow only SDKs.
Please help me find an alternative so that I can still get the poly points using my restricted API Key. I tried finding some alternatives but did not come across any different methods.

How to use Google geocoding API?

I have an Android application and I am using the Google geocoding API to get GPS coordinates for an address. Currently I am using the following URL which works correctly:
http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=1600+Amphitheatre+Parkway,+Mountain+View,+CA
The problem is, will the above API continue to work after the Google's 'new pricing changes' starting July 16, 2018? According to the Google API documentation here, https://developers.google.com/maps/documentation/geocoding/intro#GeocodingResponses, the correct way to perform geocoding is using the following format:
https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=YOUR_API_KEY
I have tried using the suggested format (created a project, enabled billing, enabled the Places and Maps APIs, created an API key, added security to the key so that only my app can access the key) but when I use the suggested format I get the error,
This IP, site or mobile application is not authorized to use this API
key
Reading other questions on StackOverflow, I found the following suggestions, among others:
Creating a server key and using it instead of the API key
Not adding restrictions to the API key
Using the first format of the API request (without the API_KEY)
Wait for 10 minutes until the new KEY becomes active
I tried all of them except 1 and none works. Regarding solution #1, according to the documentation, the API needs an API key so I cannot see why a Server key would work.
Solution 2 is risky, solution 3 is not certain that it will continue to work with the pricing changes and solution 4 does not work either (I waited for hours without success).
I even created a new API KEY and added no restrictions to it and I got a limit exceeded error.
Can anyone provide any help on this?
Based on your comment above then the quickest approach would be to reverse geocode the address with Geocoder:
if(Geocoder.isPresentt()){
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addresses;
addresses = geocoder.getFromLocationName(addressName, 3);
for(Address address : addresses){
Log.d(TAG,"Lat:" + address.getLatitude() +", Lng: " + address.getLongitude());
}
}
Using a proxy service (Solution #1) is the way to go if you are restricted to using the google Geocoding API.
Your app is being denied because google has no way of knowing what app is making the request with just the API key. If you look at the available API's, some say "for Android" and "for iOS", these are the ones that you can restrict and use natively.
Using a proxy will work (your assumption it won't is wrong) because you can restrict your API key to the IP of your service, and then require authorization from your app to use the proxy endpoint. This will protect your API key from being stolen and abused.

Why is my api key not accepted by the Google Directions (Android) request?

Whenever I include my Google Play Services API key along with my request for Google Directions like in the code below:
private String makeDirectionsURL(double originLat, double originLong, double destLat, double destLong)
{
StringBuilder url = new StringBuilder();
//first part of url//
url.append("https://maps.googleapis.com/maps/api/directions/json?");
//start adding parameters//
//origin coordinates
url.append("origin="+originLat+","+originLong);
//destiniation coordinates
url.append("&destination=");
url.append(destLat+","+destLong);
//api key
url.append("&key=");
url.append(getResources().getString(R.string.google_api_key));
//NOTE: for some reason, the request suceeds when leaving out the api key
return url.toString();
}
When I include the api key as a parameter in the request, the json response shows that my request has been denied. The response reads:
{
"error_message" : "This IP, site or mobile application is not authorized to use this API key.",
"routes" : [],
"status" : "REQUEST_DENIED"
}
Yet the same api key works for my google map view - and my api console registers the accesses for the map view quota limit. Even odder yet, when I leave out the key parameter in the Directions request I get a valid JSON response.
I have a feeling that I have to generate another different api key for just the Google Directions service - but I'm not sure how to. The documentation here:
https://developers.google.com/maps/documentation/directions/#api_key
Says to visit the console and activate the Directions API service - I did.
Then it says my api key "will be available from the API Access page, in the Simple API Access section. Directions API applications use the Key for server apps." Now is where I'm confused - how can I use the key for server apps if I am accessing from a mobile device - I'm assuming this is for any webpages that wish to use the service - but what do I do for an android app. As I said, I already tried using my Simple API Access key for Android apps, which I know works, yet when I pass the same key to Google Directions - it mysteriously doesn't work...
Any help, vague guidance, or links to read up on would be really appreciated.
PS: If I can't figure this out - am I allowed to keep sending requests w/o a api key?
I think the issue is because you are trying to pass a server key which is directly tied to your server's IP address, when you should be passing an android app key.
In your Google APIs console, navigate to API's and Auth. From here you can create a new public API key.
When prompted, select Android Application
You will need to enter your device's SHA1 Certificate Fingerprint
This comes from the keystore used to sign the apk. When running an app in debug, you will most likely be using your IDE's debugging keystore. Google has a nice write up on how to get this information.
When releasing the app, you will need to sign it with your own key. You will either need to edit your API key to the new keystore SHA1 fingerprint or create a new API key.
Additionally, according to Google, you should be using a key.
All Directions API applications should use an API key. Including a key
in your request:
Allows you to monitor your application's API usage in the APIs
Console. Enables per-key instead of per-IP-address quota limits.
Ensures that Google can contact you about your application if necessary.
While I can't comment on how strictly they enforce this, I strongly encourage you to do so to avoid any issues down the road.

Google Places API Key for Android App

I have created an API Key (for Android apps) for my Android Application. It was required by google maps API. But now the same key won't work for Google Places API.
I also tried hitting the browser with the following URL:
https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJN1t_tDeuEmsRUsoyG83frY4&key=my_key
I get:
{
"error_message" : "This IP, site or mobile application is not authorized to use this API key.",
"html_attributions" : [],
"status" : "REQUEST_DENIED"
}
When I googled for an answer, I found this:
https://developers.google.com/places/training/autocomplete-android
What type of API key?
You'll need your own browser or server API key for the Google Places API before you can begin using the Place Autcomplete service. Note that an Android API key will not work for the Place Autocomplete service.
This got me confused as I do not have any URL for a web app, nor any server IP. Therefore I am confused on how to get either a Browser key or a Server key
Could anyone please help me in figuring out what sort of key is needed here? Also if I have to create a Browser key or a Server key, how can I do so?
For working with places api generate browser key because for that android key does not work.
Had same issue but this solved the problem
You need to enable the following places api
-Google Places API Web Service
And you are required to use server key for fetching the data of places.
To get a server key follow the below steps: APIs & Auth -> Credentials -> create new key -> Server key
Browser key will not work.
I had the same issue and I resolved it by doing the same.
Here you can have a look to build your Url
StringBuilder googlePlacesUrl = new StringBuilder("https://maps.googleapis.com/maps/api/place/nearbysearch/json?");
googlePlacesUrl.append("location=" + latitude + "," + longitude);
googlePlacesUrl.append("&radius=" + PROXIMITY_RADIUS);
googlePlacesUrl.append("&types=" + type);
googlePlacesUrl.append("&sensor=true");
googlePlacesUrl.append("&key=" + SERVER_KEY);
If you want to integrate Google Place Api in android project and you need a key, then just click the link below it will automatically create a key for
you and just copy that key in your project
https://developers.google.com/places/android-api/start

Google Place Autocomplete on Android

I want to create an app that autocompletes a destination text box. I read this documentation about it:
Adding Place Autocomplete to your Android App
However it says that you can't use your API key internally and that you must instead access an external web service to make the autocomplete submission and return the results to your app. I then came across this:
Place Autocomplete in response to an HTTP request
This states that you can make a request with your API key as part of the URL for the HTTP request. Can you do this internally from your app or would you have to submit that HTTP request from an external web service as well? If you can just make this HTTP request from within the app, how would I go about doing this?
Try this solution:
1) Get an application's API key from the Google console.
Create Api Key
2) Use this module from GitHub to make Google Place Auto Complete. It's easy to integrate: Android GooglePlaceAutoComplete

Categories

Resources