# Api Plugin Source: https://maps.vietmap.vn/docs/sdk-mobile/react-native/react-plugin/ A package for using the [VietMap APIs](https://maps.vietmap.vn/docs/map-api/overview/) in JS/TS. # Vietmap API plugin !!! warning "The plugin calls legacy endpoints" `@vietmap/vietmap-api` 1.1.2 calls Autocomplete v3, Search v3, Place v3, Reverse v3 and the legacy Route and TSP endpoints (`api-version`). New integrations that need the post-merger address format, toll costs or truck routing should call the [v4 APIs](https://maps.vietmap.vn/docs/map-api/overview/) directly over HTTP. ## Installation With npm: ```bash npm install --save @vietmap/vietmap-api ``` With Yarn: ```bash yarn add @vietmap/vietmap-api ``` With pnpm: ```bash pnpm add @vietmap/vietmap-api ``` Check the latest version at [https://www.npmjs.com/package/@vietmap/vietmap-api](https://www.npmjs.com/package/@vietmap/vietmap-api)
## Usage ### Import VietmapApi: ```typescript import { VietmapApi } from '@vietmap/vietmap-api'; ``` Create an instance using apiKey: ```typescript const VietmapApi = new VietmapApi({ apiKey: VIETMAP_API_KEY }) ``` ## Examples ### Reverse Updating Reverse 3.0 API is a valuable resource for developers who want to incorporate location search features into their applications while achieving optimal performance. With its intelligent search algorithms and techniques, this latest version can swiftly deliver precise search results for users. This API is a powerful tool that can help enhance the user experience of location-based applications. ```typescript const reverseResponse = await vietmapApi.reverse({ latitude: 35.72379, longitude: 51.33417, }); ``` ### Autocomplete Updating Autocomplete 3.0 API is a valuable resource that allows developers to integrate autocomplete functionality into their applications. This API is designed to help users quickly find and select items from a large set of options by suggesting potential matches as they type. The API is built on a machine-learning model that analyzes user input and suggests potential matches based on the context of the search. This model can be updated in real-time, allowing the API to continuously improve its suggestions as more data becomes available. ```typescript const autoCompleteSearchResponseList = await vietmapApi.autoCompleteSearch( new SearchRequest({ text: 'Vietmap' }), ); ``` ### Search - Geocode Updating Geocode 3.0 API is a powerful tool for developers to integrate location search functionality into their applications with optimized performance. Additionally, this latest version utilizes intelligent search algorithms and methods to provide accurate and speedy search results for users. ```typescript const searchResponseList = await vietmapApi.search( new SearchRequest({ text: 'Vietmap' }), ); ``` ### Routing A Route Maps API is a feature provided by VIETMAP that allows developers to calculate and display the optimal route between two or more locations on a map. With a Route Maps API, developers can specify the start and end points of a journey, along with any additional constraints such as preferred mode of transportation, and retrieve a detailed route that can be displayed on a map. The API may also provide information such as the total distance, estimated travel time, and turn-by-turn directions. Developers can use Route Maps APIs to create applications that help with navigation, transportation planning, and logistics management. ```typescript const res = await vietmapApi.route( [[10.79628438955497,106.70592293472612], [10.801891047584164,106.70660958023404]], new RouteRequest({ vehicle: 'car',apikey: envVariables.VIETMAP_API_KEY,points_encoded: true, optimize:true}), ) ``` ### Polyline decode The routing API will respond to the route path in the encrypted string. You must use the Polyline decode to convert it to `LatLng`. ```typescript const polyline = new Polyline() const listLatLng = polyline.decode('c_hjS}s{`A{C}`@',5) ```

[

](https://maps.vietmap.vn) Email us: [maps.info@vietmap.vn](mailto:maps.info@vietmap.vn) Contact for [support](https://maps.vietmap.vn/web#contact-section) Vietmap API document [here](https://maps.vietmap.vn/docs/map-api/overview/) Have a bug to report? [Open an issue](https://github.com/vietmap-company/vietmap_api_js_plugin/issues). If possible, include a full log and information that shows the issue. Have a feature request? [Open an issue](https://github.com/vietmap-company/vietmap_api_js_plugin/issues). Tell us what the feature should do and why you want the feature.