I am using Places.GeoDataApi for Android and I get different search results depending on the location of the device performing the request. I need the results to be consistently located inside the bounds. I don't see where that could be setup in the getAutocompletePredictions request. Is there anything I am missing?
I get address/place autocomplete suggestions using the GoogleApiClient and Places API through:
Places.GeoDataApi.getAutocompletePredictions()
The method requires a GoogleApiClient object, a String to autocomplete, and a LatLngBounds object to limit the search range. This is what my usage looks like:
LatLngBounds bounds = new LatLngBounds(new LatLng(38.46572222050097, -107.75668023304138),new LatLng(39.913037779499035, -105.88929176695862));
GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.addApi(Places.GEO_DATA_API)
.build();
PendingResult<AutocompletePredictionBuffer> results =
Places.GeoDataApi.getAutocompletePredictions(googleApiClient, "Starbucks", bounds, null);
Version in use: com.google.android.gms:play-services-location:8.3.0
Documentation:
https://developers.google.com/places/android/autocomplete
Good news. As of April 2018 Google added possibility to specify how to treat the bounds in autocomplete predictions. Now you can use the getAutocompletePredictions() method of GeoDataClient class with boundsMode parameter
public Task<AutocompletePredictionBufferResponse> getAutocompletePredictions (String query, LatLngBounds bounds, int boundsMode, AutocompleteFilter filter)
boundsMode - How to treat the bounds parameter. When set to STRICT predictions are contained by the supplied bounds. If set to BIAS predictions are biased towards the supplied bounds. If bounds is null then this parameter has no effect.
source: https://developers.google.com/android/reference/com/google/android/gms/location/places/GeoDataClient
You can modify your code to something similar to:
LatLngBounds bounds = new LatLngBounds(new LatLng(38.46572222050097, -107.75668023304138),new LatLng(39.913037779499035, -105.88929176695862));
GeoDataClient mGeoDataClient = Places.getGeoDataClient(getBaseContext());;
Task<AutocompletePredictionBufferResponse> results =
mGeoDataClient.getAutocompletePredictions("Starbucks", bounds, GeoDataClient.BoundsMode.STRICT, null);
try {
Tasks.await(results, 60, TimeUnit.SECONDS);
} catch (ExecutionException | InterruptedException | TimeoutException e) {
e.printStackTrace();
}
try {
AutocompletePredictionBufferResponse autocompletePredictions = results.getResult();
Log.i(TAG, "Query completed. Received " + autocompletePredictions.getCount()
+ " predictions.");
// Freeze the results immutable representation that can be stored safely.
ArrayList<AutocompletePrediction> al = DataBufferUtils.freezeAndClose(autocompletePredictions);
for (AutocompletePrediction p : al) {
CharSequence cs = p.getFullText(new CharacterStyle() {
#Override
public void updateDrawState(TextPaint tp) {
}
});
Log.i(TAG, cs.toString());
}
} catch (RuntimeExecutionException e) {
// If the query did not complete successfully return null
Log.e(TAG, "Error getting autocomplete prediction API call", e);
}
I hope this helps!
I got the same problem.
Unfortunately, there is no way to get places in specific bounds using Google Places API Android.
However, you can still use Nearby Search using Google Places API Web Service.
Documentation here :
https://developers.google.com/places/web-service/search?hl=fr
You should then be able to set the bounds in parameters, and get the places inside the bounds from the JSON response, as explained in this answer :
https://stackoverflow.com/a/32404701/5446285
Related
I want to extract drawing extents from Civil3D dwg's using Design Automation.
If I use the code below:
static public Extents3d GetExtents(Database db) {
try {
//db.UpdateExt(true);
return new Extents3d(db.Extmin, db.Extmax);
} catch {
return new Extents3d();
}
}
Then I get the following result which is correct:
Min: [2538909.32, 330601.59, 0.00]
Max: [2540326.77, 331107.96, 0.00]
However, if I call db.UpdateExt(true) before or if I simply iterate all entities in model space with the code below, I get a min bound that is at origin:
static public Extents3d GetExtents(Database db) {
try {
var TxMng = db.TransactionManager;
using(var Tx = TxMng.StartTransaction()) {
var btr = Tx.GetObject(
db.CurrentSpaceId, OpenMode.ForRead)
as BlockTableRecord;
foreach(var id in btr) {
var entity = Tx.GetObject(id, OpenMode.ForRead)
as Entity;
extents.AddExtents(entity.GeometricExtents);
}
Tx.Commit();
}
return extents;
} catch {
return new Extents3d();
}
}
Outputs:
Min: [0.00, 0.00, 0.00]
Max: [2540326.77, 331107.96, 0.00]
Also opening the dwg in AutoCAD vanilla and doing a zoom extents will use this huge/invalid extents. So I think Civil knows that some entities should not be included when computing extents or is it something else?
I would like to be able to compute extents using the second approach (at least a modified working version of it) as it offers more granularity over what entities we want to consider if later on we have some more advanced requirements.
When iterating the entities to compute the extends, it is OK we do not include the entity AeccDbNetworkPartConnector. You can use the API entity.GetRXClass().Name to get the name AeccDbNetworkPartConnector, which can help filter out these entities.
I am using google-map-react to render maps in my react app.I am displaying dynamic number of markers on the map.I need to fit the view of map so that it just encloses all the markers.I went through this thread but found it a bit complicated.Can anyone please give me an overview of how this can be done?
It happens that I had to do the exact same thing recently. I found that existing libs were more getting on my way than actually helping so I just went with writing my own component.
In case you decide going the same way - here's how to do what you want:
First - you need to get the bounds object enclosing all your markers. Here we assume that this.state.markers contains an array of google.maps.Marker objects
Your component could have the following method to do that:
getObjectsBounds(){
let objectsBounds = new google.maps.LatLngBounds();
Object.values(this.state.markers).map((marker) => {
let lat = parseFloat(marker.getPosition().lat());
let long = parseFloat(marker.getPosition().lng());
let point = new google.maps.LatLng(lat, long);
objectsBounds.extend(point);
});
return objectsBounds;
}
Now we just use fitBounds on the above funtion's return results. Here we assume that this.map is your gmap, i.e. what google.maps.Map( ... your args ... ) returns.
fitBounds(){
let bounds = this.getObjectsBounds();
this.map.fitBounds(bounds);
}
I posted about it an issue https://code.google.com/p/gmaps-api-issues/issues/detail?id=8387&thanks=8387&ts=1437921771
But still I want to know if anybody faced this and know the solution for this...
First I'm using nearBySearch http web service to get places around me via:
https://maps.googleapis.com/maps/api/place/nearbysearch/output?parameters
https://developers.google.com/places/webservice/search
Second step I use GeoDataApi.getPlaceById API for Android to get more details
about the places from step 1 above.
https://developers.google.com/places/android/place-details
I assume that PlaceId is 'Global reference' across all Google maps platforms.
The bug is: Sometimes (and even not so rarely) PlaceID's from nearBySearch does't exist in GeoDataApi.getPlaceById, and instead I get result of this form:
{
"html_attributions" : [],
"status" : "INVALID_REQUEST"
}
PlaceID for example: ChIJJcoXzj8oAxURY8ZGJx4crNo
Edit: This is the android code:
Places.GeoDataApi.getPlaceById(mGoogleApiClient, stringIDSArray).setResultCallback(new ResultCallback<PlaceBuffer>() {
#Override
public void onResult(PlaceBuffer places) {
if (places.getStatus().isSuccess()) {
//Actually for the specified PlaceID (ain't here real "Array") we expect loop iteration
for (int i=0; i<places.getCount(); i++) {
//str is NULL for the problematic PlaceID
String str = places.get(i).getName().toString();
}
}
places.release();
}
});
Thanks,
I am using a gmap autocomplete and sometimes the user doesn't hit any choice in the suggestion list. For example he types "Paris" in the input field and believes the search will be performed with Paris, however has the 'place_changed' of the gmap autcomplete was never called, the search cannot be perfomed.
How can I select by default the first choice of the suggestion list when the user doesn't make any choice ? I believe I could adapt the solution provided for the "enter issue" described here (Google maps Places API V3 autocomplete - select first option on enter) with a blur event handling, however this doesn't work.
Any hint ?
I think this is kind of defeating the purpose of the auto complete.
You could just retrieve the autocomplete predictions pro grammatically like so:
function initialize()
{
var service = new google.maps.places.AutocompleteService();
service.getQueryPredictions({ input: 'some address' }, callback);
}
function callback(predictions, status)
{
if (status != google.maps.places.PlacesServiceStatus.OK)
{
alert(status);
return;
}
// Take the first result
var result = predictions[0]
// do as you wish with the result
}
Hope that helps
I wanted to save the google map into an image from a webpage.
while i was searching for that i got this program.
http://www.codres.de/downloads/gms.exe[^]
besides other alternatives like print screen i wanted to use a program or map api which can save a specified dimension of google map instead of the screen.
i have used browser component in c# for http access and for displaying certain webpages.
I want to know whether there are options to capture the browser screen to image using any c# functionality or even the browser component would have given such options. just a guess.
i would like to have answers, suggestions on how to capture the map with custom dimension and zoom size to an image.
I used this to get captcha Image from the current page, so you can use similar code just amend the imageID to point to the google map image and use this solution for zooming.
public string newsavefunction(WebBrowser webBrowser1)
{
IHTMLDocument2 doc = (IHTMLDocument2)webBrowser1.Document.DomDocument;
IHTMLControlRange imgRange = (IHTMLControlRange)((HTMLBody)doc.body).createControlRange();
string imagename = string.Empty;
try
{
foreach (IHTMLImgElement img in doc.images)
{
imgRange.add((IHTMLControlElement)img);
imgRange.execCommand("Copy", false, null);
using (Bitmap bmp = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap))
{
bmp.Save(#"F:\captchaimages\captchapic.jpg");
}
imagename = img.nameProp;
break;
}
}
catch (System.Exception exp)
{ }
return imagename;
}