Can I get full address with OSRM Backend

664 Views Asked by At

I want to find one what can inteads of google api with cheap cost so that I can get city , postal code, lat long, neighborhood from address string. I researhed and found osrm backend. I built it in my local. But It not support to get full address. http://project-osrm.org/docs/v5.5.1/api/#general-options

Can I get full address with OSRM Backend?

1

There are 1 best solutions below

0
On

It is unlikely, that you can resolve an address by using OSRM backend, because its main functions are routing or map matching.

You should use a geocoder instead, like in the demo below:

animated map

'use strict';

var myMap = L.map('mapId').setView([21.0278, 105.8342], 13);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  attribution: '&copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors'
}).addTo(myMap);

var search = new GeoSearch.GeoSearchControl({
  provider: new GeoSearch.OpenStreetMapProvider(),
  style: 'bar',
  showPopup: true,
  popupFormat: ({
      query,
      result
    }) => result.label + 
    ', longitude: ' + parseFloat(result.x).toFixed(6) +
    ', latitude: ' + parseFloat(result.y).toFixed(6)
});

myMap.addControl(search);
html, body { 
  margin: 0;
  padding: 0;
}

#mapId {
  position: absolute;
  width: 100%;
  height: 100%;
}
<link type="text/css" rel="stylesheet" href="https://cdn.jsdelivr.net/npm/leaflet@1/dist/leaflet.min.css">
<script src="https://cdn.jsdelivr.net/npm/leaflet@1/dist/leaflet-src.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/leaflet-geosearch@3/dist/bundle.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/leaflet-geosearch@3/dist/geosearch.min.css">

<div id="mapId"></div>