0

When I call the HERE Geocoder Autocomplete API endpoint :

https://autocomplete.geocoder.ls.hereapi.com/6.2/suggest.json
?apiKey={YOUR_API_KEY}
&query=Pariser+1+Berl
&beginHighlight=<b>
&endHighlight=</b>

as explained in the documentation using jsonp (because of CORS error), I get a kinda weird error :

Console Error Screenshot

"Error: JSONP injected script did not invoke callback."

"message: "Http failure response for https://autocomplete.geocoder.ls.hereapi.com/6.2/suggest.json?query=23 Rue de &beginHighlight=<b>&endHighlight=</b>&apiKey=****&callback=ng_jsonp_callback_0: 0 JSONP Error"

Although this is a 200 OK:

Network Tab screenshot

Response screenshot

Here is my service :

@Injectable({
  providedIn: 'root'
})
export class LocationService {

  constructor(
    private http: HttpClient,
  ) { }

  public getSuggestions(query: string): Observable<Suggestion[]> {
    const options = 'beginHighlight=<b>&endHighlight=</b>';
    const url = `${environment.hereDevelopper.suggestionAPIURL}?query=${query}&${options}&apiKey=${environment.hereDevelopper.key}`;

    return this.http.jsonp<Suggestion[]>(url, 'callback').pipe(map(suggestions => suggestions));
  }
}

So my question is any ideas or "suggestions"?

1 Answer 1

0

so I ended up not using Jsonp.

public getSuggestions(query: string): Observable<Suggestion[]> {
    const options = 'beginHighlight=<b>&endHighlight=</b>';
    const url = `${environment.hereDevelopper.suggestionAPIURL}?query=${query}&${options}&apiKey=${environment.hereDevelopper.key}`;

    return Observable.create(observer => {
      fetch(url)
        .then(response => response.json())
        .then(suggestions => {
          observer.next(suggestions.suggestions);
          observer.complete();
        })
        .catch(err => observer.error(err));
    });
  }

I just use fetch instead, but if someone has a solution with jsonp, I'm pretty curious.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.