Google Places Autocomplete is not working Sometimes in Xamarin Android Project - google-maps

I am implementing Google Places Autocomplete in my Xamarin Android project. (This is not a Xamarin Forms Project).
When I search first time, the autocomplete works properly but consequent searches do not work properly.
Even if the autocomplete works, if I select an item, it will not call OnActivityResult function and get back the above screen again.
Even these posts did not solve my problem
Google Places Autocomplete Can't load search results
Android onActivityResult not called / triggered
I have not set a billing account but I dont think that is the problem because it works sometimes. How can I solve this issue?
(Please note this is not a duplicate question since I could not find any questions like this)
This is the code I am using to open Google Places Autocomplete view
private void BtnLocationOnClick(object sender, EventArgs e)
{
List<Place.Field> fields = new List<Place.Field>();
fields.Add(Place.Field.Id);
fields.Add(Place.Field.Name);
fields.Add(Place.Field.LatLng);
fields.Add(Place.Field.Address);
Intent intent = new Autocomplete.IntentBuilder(AutocompleteActivityMode.Overlay, fields)
.SetCountry("US")
.Build(this);
StartActivityForResult(intent, 1);
}
Once the item is selected OnActivityResult function need to be called
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
if (requestCode == 1)
{
if (resultCode == Android.App.Result.Ok)
{
Place place = Autocomplete.GetPlaceFromIntent(data);
txtLocation.Text = place.Name;
googleMap.AnimateCamera(CameraUpdateFactory.NewLatLngZoom(place.LatLng, 15));
}
}
}

Enabling billing on your project is mandatory for the Places API (or any other Maps API) to work. Otherwise you are limited to 1 request per day.
Follow Google's get started guide to create a billing account and link it to your project.
Also make sure that the Places API is enabled on your project too.
Hope this helps!

Related

Periscope (by Twitter) comments feed – how to retrieve viewer messages to my script?

I want to build some automation based on comments by viewers of my live Periscope broadcast.
There is no public API for that. Maybe there is some private API feature I could use for now?

Google Places Autocomplete API Consumption

I'm using google maps API on my company, and we're facing some issues with the consumption of the API.
We use the Javascript API, loading the map, and we geocode some address and make some routes. Everything normal.
But we use the Autocomplete in some cases, to allow the user to input the location he's searching.
So, I define the autocomplete like this:
var autocomplete = new google.maps.places.Autocomplete(
document.getElementById('textBox'),
{ types: [] });
When the user select an option, we call the function
autocomplete.addListener('place_changed', doSomething);
get the place and do more things
function doSomething() { var place =
autocomplete.getPlace();
//more code }
Everything works fine, but when the user start typing, it's been consuming the Google Places API Web Service. Is it right?
I thought it would only consume the Javascript API when we loads the map, and that's it.
And the weird thing is that, on the developer's console, the utilization of the API started few days ago (30/06/2016), and we have a gap of no utilization of this API (between 3th and 10th of July), and yesterday we reach the limit of 1000 uses.
Am I doing something wrong? What can I do?
Sorry if this is not the right place for the question, and if it's not, move it or tell me so I can open in the new place.
Thanks
You can find an answer in this blog post:
http://googlegeodevelopers.blogspot.com.es/2016/06/building-for-scale-updates-to-google.html
Look at 4. Starting from June 22, 2016 Google counts client-side requests against the corresponding web service APIs. Apparently, some of your domains were "grandfathered", but the new ones will follow the new policy.

How to use inbuilt google apps in android application using android studio?

I'm developing an Android application and I need to open the inbuilt google maps which is present in the mobile from the application which I'm creating. On clicking the button, it should open the inbuilt google maps. Similar way I need to open camera. Where and how to do this? Kindly help me.
You can open another app via Intent. You can issue an intent with explicit package name (see start application knowing package name).
This will work fine for Google Maps, but for Camera the situation is more complicated.
There is no one official Google camera app available on all android devices, some manufacturers use their custom versions, and don't use the same package name.
Luckily, all camera apps are expected to register for the MediaStore.ACTION_IMAGE_CAPTURE intent. By probing the subscribers of this intent you can find one or more package names that you can launch as camera apps.
for google map app
String uriBegin = "geo:" + latLng;
String query = latLng + "(" + 1 + ")";
String encodedQuery = Uri.encode(query);
String uriString = uriBegin + "?q=" + encodedQuery + "&z=16";
Uri uri = Uri.parse(uriString);
Intent mapIntent = new Intent(android.content.Intent.ACTION_VIEW, uri);
startActivity(mapIntent);

Google geocoding API setup finding the correct ClientID and Secret

I am building a java web application that requires googles geocoding service as defined on https://developers.google.com/maps/documentation/geocoding/ . My application is all setup and everything works, I am now attempting to sign my requests to allow for additional features from the API such as additional rate limits billing ect...
The problem I am having is I cant seem to get a proper Client Id and Key that works with the geocoding API. I used just about every sensible combination of id and key from the API Access tab on Google's API console. To test my credentials and I have copied the PHP code directly from google at http://gmaps-samples.googlecode.com/svn/trunk/urlsigning/index.html to ensure my requests are signed correctly. I watched a google developers video about this topic (https://www.youtube.com/watch?v=ODeXo7YIwVg) and it shows this being done for a Google business account, After reading through Google's API docs it would seem you do not have to have a business account to use the geocoding service however I cant seem to get a valid client ID and Key to work for me. Does anyone know of the correct setup to use this service on a non business account? or is it even possible? (keep in mind this a server to server connection)
If anyone needs additional information let me know. I would be grateful for any suggestions.
edit: Looking at the Usage Limits listed on https://developers.google.com/maps/documentation/geocoding/#Limits you see it implies that you can use the Geocoding API without a business account.... but how?
I went through the documentation and as you have rightly pointed out you do not need a business account to use the Geocoding API. If you have a non business account then you only need to pass the API key. Client ID is required only if you have a business account. The key itself is unique as mentioned below :
https://developers.google.com/console/help/#WhatIsKey
An API key is a unique key that you generate using the Console. When your application needs to call an API that's enabled in this project, the application passes this key into all API requests as a key=API_key parameter. Use of this key does not require any user action or consent, does not grant access to any account information, and is not used for authorization.
According to the link below the Client ID is used instead of key in the case of Business Accounts.
https://developers.google.com/maps/articles/v2tov3#newkey
If you are a Maps for Business customer, you will need to use a Client ID in place of a Key. Note that the two cannot be used together. Client IDs are similar to keys, but with the following differences:
Maps for Business applications using a Client ID may have access to additional features or limits, such as Maps Analytics.Your Client ID will be given to you by Google Enterprise Support. You do not need to use the API Console.
When loading the Google Maps JavaScript API, you will use the client parameter instead of the key parameter.
I'm guessing the same principle applies to the Geocoding API. If you want the additional feature that are not part of non business account you will have to get a Business Account.
I ran the following code using only the key to sign my request in Java and it works perfectly.
public static String getAddress(String latitude, String longitude){
String address = null;
try {
final String inputurl = "http://maps.googleapis.com/maps/api/geocode/xml?latlng="+ latitude + "," + longitude + "&sensor=true";
// Sign the URL using key
String url = getRequestURL(inputurl);
url = "http://maps.googleapis.com" + url;
final URL google = new URL(inputurl);
final URLConnection geocode = google.openConnection();
final BufferedReader in = new BufferedReader(new InputStreamReader(
geocode.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
address += inputLine;
}
in.close();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return null;
}
public static String getRequestURL(final String inputurl) throws IOException,
InvalidKeyException, NoSuchAlgorithmException, URISyntaxException {
// Convert the string to a URL so we can parse it
final URL url = new URL(inputurl);
final URLSigner signer = new URLSigner("*INSERT YOUR KEY HERE*");
final String request = signer.signRequest(url.getPath(), url.getQuery());
return request;
}

Find all parks for a given zipcode with google maps

I'm trying to use the Google maps geocode API to return all parks for a given zip code. It seems that if I have a park name I have no problem returning the data. Such as
http://maps.googleapis.com/maps/api/geocode/json?address=Kerry+Park+98122&sensor=false
However, if i search for parks for a zip code
http://maps.googleapis.com/maps/api/geocode/json?address=Parks+near+98122&sensor=false
I get any result for the zip code with parks in the address. I tried using lanlng but that has the same problem. It seems that Google doesn't allow types[] in query just the results which is unfortunate.
If I search for "parks near 98122" on maps.google.com I get all the results but it doesn't seem to be using the same API.
I requested a Google maps Places api key which I think is what I need.
I guess my questions are:
a) am I missing something here?
b) I'm not stuck with Google API are their others that will output JSON results for all parks by zip. I looked briefly into Bing and Yahoo to no avail.
Thanks.
Use Google Places API and the text search.
Change the [zipcode] and the key [apikey]:
https://maps.googleapis.com/maps/api/place/textsearch/json?query=park+in+[zipcode]&key=[apikey]
The Google geocoder API doesn't have a provision for specifying a "type" such as "park" in the query. It will identify the feature type in the response, but you can't put it in the the request.
You might be able to do what you want in the Google Places API, now out for developer preview. I haven't tried it. You still can't specify a type in the request, but you specify a location and radius, and it returns all places, and each place has one or more associated type codes (which might include park). You can search through the returned results to see if parks appear. See http://code.google.com/apis/maps/documentation/places/
I just worked on this, I am not using a zip code, but you can take a zip code and get a lat/lng pair. The lat/lng pair already used here(map center set).
This is the query to get parks. I will say it is probably not absolute(only major parks) and there is that 20 limit.
This is from their docs btw, using Places api, also this code is from ReactJS hence ref eg. "current"
const plotParks = (parks) => {
// array of parks, use marker to plot on map and fit bounds to center
}
const service = new window.google.maps.places.PlacesService(mapTarget.current);
// radius in meters so I added mile to radius, seems correct, formula pulled from SO ha
const radiusInMeters = (Math.round(10000*(radiusMiles*5280 / 3.281))/10000);
service.nearbySearch(
{location: mapTarget.current.getCenter(), radius: radiusInMeters, type: ['park']},
(results, status, pagination) => {
if (status !== 'OK' || !results.length) {
alert('No parks found near you, try increasing your radius or try a new address');
} else {
plotParks(results);
}
});
do ctrl+f for 'store' to jump to the code
https://developers.google.com/maps/documentation/javascript/places