住所をジオコード化したり、ジオコード化したりすることは、位置情報を利用したアプリケーションの一般的な要件です。 HERE Geocoding and Search の API は、 HERE サービスの検索機能とジオ コーディング機能のロックを解除し、開発者に差別化された位置情報対応アプリケーションを作成するための比類のない柔軟性を提供します。
これらのすべての機能には、 Map API のサービスモジュール () を使用してアクセスmapsjs-service.jsでき、マップアプリケーションに簡単に統合できます。
ジオ コーディングの結果を地図に表示しています
次の例で は、住所 200 S Mathilda Ave, Sunnyvale, CA をジオコード化し、地図の返された場所にマーカーを配置する方法を示します。
コードはジオ コーディングリクエストを送信し、結果を処理するコールバック関数を提供します。 リクエストでは、 HERE HERE Geocoding and Search の API でサポートされているパラメータ名に一致するメンバーを含むオブジェクトリテラルが使用されます。 指定したオブジェクトリテラルの内容は、 Maps API によって URL パラメータに変換されます。 パラメータオブジェクトには、 HERE Geocoding and Search の API によって認識された任意のパラメータを含めることができます。
// Instantiate a map and platform object:var platform =newH.service.Platform({'apikey':'{YOUR_API_KEY}'});// Get an instance of the geocoding service:var service = platform.getSearchService();// Call the geocode method with the geocoding parameters,// the callback and an error callback function (called if a// communication error occurs):
service.geocode({q:'200 S Mathilda Ave, Sunnyvale, CA'},(result)=>{// Add a marker for each location found
result.items.forEach((item)=>{
map.addObject(newH.map.Marker(item.position));});}, alert);
次に、ドイツのベルリンで指定された位置のアドレスを取得する例を示します( 52.5309 ° N 13.3847 ° E )。 結果が地図に表示され、取得した住所の場所を示す情報バブルが表示されます。
// Instantiate a map and platform object:var platform =newH.service.Platform({'apikey':'{YOUR_API_KEY}'});// Get an instance of the search service:var service = platform.getSearchService();// Call the reverse geocode method with the geocoding parameters,// the callback and an error callback function (called if a// communication error occurs):
service.reverseGeocode({at:'52.5309,13.3847,150'},(result)=>{
result.items.forEach((item)=>{// Assumption: ui is instantiated// Create an InfoBubble at the returned location with// the address as its contents:
ui.addBubble(newH.ui.InfoBubble(item.position,{content: item.address.label
}));});}, alert);
// Instantiate a map and platform object:var platform =newH.service.Platform({'apikey':'{YOUR_API_KEY}'});// Get an instance of the search service:var service = platform.getSearchService();// Call the "autosuggest" method with the search parameters,// the callback and an error callback function (called if a// communication error occurs):
service.autosuggest({// Search queryq:'Chicago ORD',// Center of the search contextat:'38.71014896078624,-98.60787954719035'},(result)=>{let{position, title}= result.items[0];// Assumption: ui is instantiated// Create an InfoBubble at the returned location
ui.addBubble(newH.ui.InfoBubble(position,{content: title
}));}, alert);