Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get stopover towns using the Google Maps API (directions)

I am new to the Google Maps API (3.0). I would like to get stopover cities based on a direction query to the Maps API and did not find any documentation on this specific topic so far.

https://developers.google.com/maps/documentation/javascript/directions#Steps

I am getting a direction based on Address A and address B. I would like to know every city that a user would cross during his journey. I found some information about way points (stopovers) but these relate to every stop or street change. I couldn't find any core object so far...

like image 493
Yann Avatar asked Feb 01 '13 07:02

Yann


2 Answers

What I would do:

  1. Use the RouteBoxer to find bounds containing the route (fairly small ones)
  2. Use the Places API to return Places of types of city_hall, local_government_office or library (maybe tune that choice a little) inside those bounds.
  3. Take the town data out of those responses, sort them for unique results, then use those.

Proof of concept, will require tuning for types of locations, distance and area where you are doing the search. Depending on the use and the length of the route, it might be better to use the reverse geocoder on points at some regular interval along the road (100 meters or 1000 meters), that might be quicker and won't use up the Places API quota.

like image 156
geocodezip Avatar answered Oct 15 '22 05:10

geocodezip


I found a alternate solution for this. We can get the main cities using two points using Here Maps Android Guide or Here Maps API request .I used the API request

It returns the longitude and latitude of main cities in the API Response. From that data we can use Google API's Geocoder to find the city names

Here maps API request URL would be like this:

https://route.api.here.com/routing/7.2/calculateroute.json ?app_id={YOUR_APP_ID} &app_code={YOUR_APP_CODE} &waypoint0=geo!52.5,13.4 &waypoint1=geo!52.5,13.45 &mode=fastest;car;traffic:disabled

Response :(route[0].leg[0].maneuver contains the main ponts)

{
"response": {
    "metaInfo": {
        "timestamp": "2019-08-25T11:32:54Z",
        "mapVersion": "8.30.99.156",
        "moduleVersion": "7.2.201933-4954",
        "interfaceVersion": "2.6.66",
        "availableMapVersion": [
            "8.30.99.156"
        ]
    },
    "route": [
        {
            "waypoint": [
                {
                    "linkId": "+842950268",
                    "mappedPosition": {
                        "latitude": 7.6005434,
                        "longitude": 80.0758708
                    },
                    "originalPosition": {
                        "latitude": 7.5999999,
                        "longitude": 80.0769999
                    },
                    "type": "stopOver",
                    "spot": 0.4595336,
                    "sideOfStreet": "neither",
                    "mappedRoadName": "Kuliyapitiya-Hettipola Road",
                    "label": "Kuliyapitiya-Hettipola Road - B243",
                    "shapeIndex": 0,
                    "source": "user"
                },
                {
                    "linkId": "-843192951",
                    "mappedPosition": {
                        "latitude": 7.4799508,
                        "longitude": 80.3700687
                    },
                    "originalPosition": {
                        "latitude": 7.48,
                        "longitude": 80.3699999
                    },
                    "type": "stopOver",
                    "spot": 0.3064516,
                    "sideOfStreet": "right",
                    "mappedRoadName": "",
                    "label": "",
                    "shapeIndex": 313,
                    "source": "user"
                }
            ],
            "mode": {
                "type": "fastest",
                "transportModes": [
                    "car"
                ],
                "trafficMode": "disabled",
                "feature": []
            },
            "leg": [
                {
                    "start": {
                        "linkId": "+842950268",
                        "mappedPosition": {
                            "latitude": 7.6005434,
                            "longitude": 80.0758708
                        },
                        "originalPosition": {
                            "latitude": 7.5999999,
                            "longitude": 80.0769999
                        },
                        "type": "stopOver",
                        "spot": 0.4595336,
                        "sideOfStreet": "neither",
                        "mappedRoadName": "Kuliyapitiya-Hettipola Road",
                        "label": "Kuliyapitiya-Hettipola Road - B243",
                        "shapeIndex": 0,
                        "source": "user"
                    },
                    "end": {
                        "linkId": "-843192951",
                        "mappedPosition": {
                            "latitude": 7.4799508,
                            "longitude": 80.3700687
                        },
                        "originalPosition": {
                            "latitude": 7.48,
                            "longitude": 80.3699999
                        },
                        "type": "stopOver",
                        "spot": 0.3064516,
                        "sideOfStreet": "right",
                        "mappedRoadName": "",
                        "label": "",
                        "shapeIndex": 313,
                        "source": "user"
                    },
                    "length": 40642,
                    "travelTime": 2159,
                    "maneuver": [
                        {
                            "position": {
                                "latitude": 7.6005434,
                                "longitude": 80.0758708
                            },
                            "instruction": "Head <span class=\"heading\">northeast</span> on <span class=\"street\">Kuliyapitiya-Hettipola Road</span> <span class=\"number\">(B243)</span>. <span class=\"distance-description\">Go for <span class=\"length\">604 m</span>.</span>",
                            "travelTime": 52,
                            "length": 604,
                            "id": "M1",
                            "_type": "PrivateTransportManeuverType"
                        },
                        {
                            "position": {
                                "latitude": 7.6054466,
                                "longitude": 80.0782084
                            },
                            "instruction": "Turn <span class=\"direction\">right</span> onto <span class=\"next-street\">Wariyapola-Hettipola Road</span> <span class=\"number\">(B079)</span>. <span class=\"distance-description\">Go for <span class=\"length\">18.9 km</span>.</span>",
                            "travelTime": 910,
                            "length": 18937,
                            "id": "M2",
                            "_type": "PrivateTransportManeuverType"
                        },
                        {
                            "position": {
                                "latitude": 7.6197481,
                                "longitude": 80.2457178
                            },
                            "instruction": "Turn <span class=\"direction\">left</span> onto <span class=\"next-street\">Wariyapola-Hettipola Road</span> <span class=\"number\">(B079)</span>. <span class=\"distance-description\">Go for <span class=\"length\">25 m</span>.</span>",
                            "travelTime": 5,
                            "length": 25,
                            "id": "M3",
                            "_type": "PrivateTransportManeuverType"
                        },
                        {
                            "position": {
                                "latitude": 7.6198554,
                                "longitude": 80.2459216
                            },
                            "instruction": "Take the <span class=\"exit\">3rd exit</span> from Wariyapola Roundabout roundabout onto <span class=\"next-street\">Kurunegala-Padeniya Road</span> <span class=\"number\">(AA010)</span>. <span class=\"distance-description\">Go for <span class=\"length\">19.6 km</span>.</span>",
                            "travelTime": 1039,
                            "length": 19569,
                            "id": "M4",
                            "_type": "PrivateTransportManeuverType"
                        },
                        {
                            "position": {
                                "latitude": 7.4887598,
                                "longitude": 80.3620291
                            },
                            "instruction": "Continue straight ahead. <span class=\"distance-description\">Go for <span class=\"length\">364 m</span>.</span>",
                            "travelTime": 36,
                            "length": 364,
                            "id": "M5",
                            "_type": "PrivateTransportManeuverType"
                        },
                        {
                            "position": {
                                "latitude": 7.4871719,
                                "longitude": 80.3648937
                            },
                            "instruction": "Take the <span class=\"exit\">2nd exit</span> from Kurunegala Roundabout roundabout. <span class=\"distance-description\">Go for <span class=\"length\">192 m</span>.</span>",
                            "travelTime": 21,
                            "length": 192,
                            "id": "M6",
                            "_type": "PrivateTransportManeuverType"
                        },
                        {
                            "position": {
                                "latitude": 7.486732,
                                "longitude": 80.3665352
                            },
                            "instruction": "Take the <span class=\"exit\">3rd exit</span> from A10 roundabout onto <span class=\"next-street\">Kandy Road</span> <span class=\"number\">(A10)</span>. <span class=\"distance-description\">Go for <span class=\"length\">880 m</span>.</span>",
                            "travelTime": 88,
                            "length": 880,
                            "id": "M7",
                            "_type": "PrivateTransportManeuverType"
                        },
                        {
                            "position": {
                                "latitude": 7.4804449,
                                "longitude": 80.3704727
                            },
                            "instruction": "Turn <span class=\"direction\">right</span>. <span class=\"distance-description\">Go for <span class=\"length\">71 m</span>.</span>",
                            "travelTime": 8,
                            "length": 71,
                            "id": "M8",
                            "_type": "PrivateTransportManeuverType"
                        },
                        {
                            "position": {
                                "latitude": 7.4799508,
                                "longitude": 80.3700687
                            },
                            "instruction": "Arrive at your destination on the right.",
                            "travelTime": 0,
                            "length": 0,
                            "id": "M9",
                            "_type": "PrivateTransportManeuverType"
                        }
                    ]
                }
            ],
            "summary": {
                "distance": 40642,
                "trafficTime": 2159,
                "baseTime": 2159,
                "flags": [
                    "builtUpArea"
                ],
                "text": "The trip takes <span class=\"length\">40.6 km</span> and <span class=\"time\">36 mins</span>.",
                "travelTime": 2159,
                "_type": "RouteSummaryType"
            }
        }
    ],
    "language": "en-us"
}

}

like image 35
Kasun Thilina Avatar answered Oct 15 '22 04:10

Kasun Thilina