I have searched but cannot find it. So if you have something like that, or similar against Bing, it will be appreciated.
Regards Petter / Norway
|
<script src=https://maps.googleapis.com/maps/api/js?key=AIzaSyBIwzALxUPNbatRBj3Xi1Uhp0fFzwWNBkE&libraries=places&v=weekly async></script> |
|
public async Task OnFiltering(FilteringEventArgs args)
{
args.PreventDefaultAction = true;
var query = new Query();
if (args.Text != "")
{
filteredData = await JsRuntime.InvokeAsync<List<string>>("OnFillter", args.Text);
}
this.AutoCompleteObj.Filter(filteredData, null);
} |
|
window.OnFillter = function (text) {
const service = new google.maps.places.AutocompleteService();
service.getQueryPredictions({ input: text }, function (predictions) {
filterResultCount = predictions && predictions.length;
return predictions;
});
} |
Thank you for providing the sample with explanation and comments. I tried to run it but no results appeared whatever I typed. I replaced the key with my own. Still no results?
regards Petter
Hi Petter,
Based on your provided information, we suspect that the cause for the issue is if the filteredData return type mismatches with the provided type, so the variable will be returned null. We suggest you to make ensure in your application, the filteredData value type is matched to get the values in server-side as expected.
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/AutoComplete_Filter-908209660
|
filteredData = await JsRuntime.InvokeAsync<List<string>>("OnFillter", args.Text); |
Regards,
Ponmani M
It doesn't seem to work with street addresses, can you comment further?
Hi Miles,
We are validating the requirement. We will update the further details in two business days(8th July 2022).
Regards,
Udhaya Kumar D
Hi Miles,
We have validated the reported query on our end. Unfortunately, we couldn’t reproduce the reported issue as per your scenario. We suspect that the result “No records found” is produced due to API key validation may be expired.
We request you to refer to the below public documentation regarding the API key.
Documentation: https://developers.google.com/maps/documentation/javascript/get-api-key
If you still facing the issue, we request you to provide additional details about the issue as mentioned below, This will help us validate the issue further and provide you with a better solution.
Regards,
Udhaya Kumar D
I've tried to use this today but i'm getting a null for filteredData but I am getting a correct network response, I've tried using the filteredData as a list of objects of this class but no luck either.
public class AddressPredictions
{
public string description { get; set; }
public Matched_Substrings[] matched_substrings { get; set; }
public string place_id { get; set; }
public string reference { get; set; }
public Structured_Formatting structured_formatting { get; set; }
public Term[] terms { get; set; }
public string[] types { get; set; }
public class Structured_Formatting
{
public string main_text { get; set; }
public Main_Text_Matched_Substrings[] main_text_matched_substrings { get; set; }
public string secondary_text { get; set; }
}
public class Main_Text_Matched_Substrings
{
public int length { get; set; }
public int offset { get; set; }
}
public class Matched_Substrings
{
public int length { get; set; }
public int offset { get; set; }
}
public class Term
{
public int offset { get; set; }
public string value { get; set; }
}
}
It's an issue with the js here:
window.OnFillter = function (text) { const service = new google.maps.places.AutocompleteService(); service.getQueryPredictions({ input: text }, function (predictions) { filterResultCount = predictions && predictions.length; return predictions; }); return "only this returns" } |
Ensure that you have a valid Google Maps API Key and that it is properly authorized to use the Places API. You can check the Google Cloud Console to confirm that the API key is set up properly and has the correct permissions. If you use an invalid API key, then "const service = new google.maps.places.AutocompleteService()" will be returned as null and the function will not be executed.
If you still encounter any issues or problems after providing a proper valid API Key, please share the following details, which will help us to validate the issue further and provide you with a better solution.
A simple, runnable sample that illustrates the issue you are experiencing.
issue replication steps.
video illustration.
I did say I was receiving the response.
I've modified the Javascript to include a call to a .NET method and have it all working.
Javascript
window.OnFillter = function (dotNetReference, parameters) { const service = new google.maps.places.AutocompleteService(); service.getPlacePredictions( { input: parameters.text, sessiontoken: parameters.sessionId, componentRestrictions: { country: ['gb', 'ie'] }, }, function (predictions) { filterResultCount = predictions && predictions.length; dotNetReference.invokeMethodAsync('RetrievePredictions', predictions); } ); } |
Razor
protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { objRef = DotNetObjectReference.Create(this); SessionToken = Guid.NewGuid(); } } public async Task OnFiltering(FilteringEventArgs args) { args.PreventDefaultAction = true; var query = new Query(); if (args.Text != "") { parameters = new Text = args.Text, SessionId = SessionToken.ToString() }; await JSRuntime.InvokeVoidAsync("OnFillter", objRef, parameters); } } [JSInvokable] public void RetrievePredictions(List<AddressPredictions> predictions) { filteredData.Clear(); addressPredictions.Clear(); if (predictions != null) { addressPredictions = predictions; foreach (var item in predictions) { filteredData.Add(item.description); } this.AutoCompleteObj.FilterAsync(filteredData, null); } } public void Dispose() { objRef?.Dispose(); } |
AddressPredictions class has been posted above.
Rob
Thanks for the update. Please get back to us if you need any further assistance on this.