vinothvetrivel
vinothvetrivel

Reputation: 109

Is it possible to find road type using google API?

In my application need to find road type ie National Highway,By Pass Road using specific co-ordinates(13.094119, 80.198606).

I tried Google Place service and Geo-coding to find particular co-ordinates location details but many times it can't help me find out road type.

https://developers.google.com/places/web-service/

https://developers.google.com/maps/documentation/javascript/examples/geocoding-reverse

https://developers.google.com/maps/documentation/roads/speed-limits

    $httpRequest = curl_init();   
    curl_setopt($httpRequest, CURLOPT_HTTPHEADER, array("Content-Type:  application/json"));
    curl_setopt($httpRequest, CURLOPT_URL, "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=13.099765,%2080.162110&radius=500&type=Road&key=YOUR_KEY");
    $result = curl_exec($httpRequest);
    curl_close($httpRequest);
    $result = json_decode($result,true);
    foreach ($result['results'] as $key => $value) {
        if(strpos($value['vicinity'],'High Road')!== false || strpos($value['vicinity'],'NH Road')!== false || strpos($value['vicinity'],'National Road')!== false){
            echo $value['vicinity'];
        }
    }

Upvotes: 2

Views: 3142

Answers (1)

xomena
xomena

Reputation: 32128

Currently the Google Maps APIs don't expose this type of information in their responses. You can see the following feature requests in the Google issue tracker

I believe these feature requests might be interesting for you. Feel free to star them to express your interest.

UPDATE

As a workaround try to use the snap to road of Roads API for your coordinate:

https://roads.googleapis.com/v1/snapToRoads?path=13.094119%2C%2080.198606&key=YOUR_API_KEY

This will provide the following response

{
  "snappedPoints":[
    {
      "location":{
        "latitude":13.094118495151756,
        "longitude":80.19856816820958
      },
      "originalIndex":0,
      "placeId":"ChIJ0dPfJw5kUjoR1sQRTkRxOIg"
    }
  ]
}

From this response you can get the place ID of the road ChIJ0dPfJw5kUjoR1sQRTkRxOIg. Now use this place ID with geocoding service that gives you a road name at least:

https://maps.googleapis.com/maps/api/geocode/json?place_id=ChIJ0dPfJw5kUjoR1sQRTkRxOIg&key=YOUR_API_KEY

The same result in Geocoder tool:

https://google-developers.appspot.com/maps/documentation/utils/geocoder/#place_id%3DChIJ0dPfJw5kUjoR1sQRTkRxOIg

Hopefully the road name 'Grand Northern Trunk Road' gives a hint about its type.

Upvotes: 1

Related Questions