当我调用 HERE Geocoder Autocomplete API 端点时:
https://autocomplete.geocoder.ls.hereapi.com/6.2/suggest.json
?apiKey={YOUR_API_KEY}
&query=Pariser+1+Berl
&beginHighlight=<b>
&endHighlight=</b>
正如使用 jsonp 的文档中所解释的那样(由于 CORS 错误),我得到了一个奇怪的错误:
"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"
虽然这是 200 OK:
这是我的服务:
@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));
}
}
所以我的问题是任何想法或“建议”?