Giter VIP home page Giter VIP logo

Comments (8)

alex-kalanis avatar alex-kalanis commented on July 23, 2024 1

That API key is worse one here. I also trying to solve how the heck merge that into my version and make appropriate tests and it's PITA. That inconsistences between APIs on G's side is awful. It might came to v3 - just due changes in internal APIs.

from google-maps-services-php.

alex-kalanis avatar alex-kalanis commented on July 23, 2024

After through look onto example I do not know how the merged service can work, because API key is not part of GET part and instead it is sent through header as an extra param.

from google-maps-services-php.

dereuromark avatar dereuromark commented on July 23, 2024

Yes, what I merged in is working
But you are right, the headers key for it seems not needed, query string part seems to suffice.

from google-maps-services-php.

dereuromark avatar dereuromark commented on July 23, 2024

Example in my CakePHP app:

$gmaps = new Client(['key' => Configure::readOrFail('google.apikey.routes')]);

        $x = [
            'location' =>
                [
                    'latLng' =>
                        [
                            'latitude' => 37.419734,
                            'longitude' => -122.0827784,
                        ],
                ],
            'sideOfRoad' => true,
        ];
        $y =[
            'location' =>
                [
                    'latLng' =>
                        [
                            'latitude' => 37.41767,
                            'longitude' => -122.079595,
                        ],
                ],
        ];

        $params = [
            'intermediates' =>
            [
                [
                    'location' =>
                        [
                            'latLng' =>
                                [
                                    'latitude' => 37.412734,
                                    'longitude' => -122.0107784,
                                ],
                        ],
                ],
            ],
            'travelMode' => 'DRIVE',
            'routingPreference' => 'TRAFFIC_AWARE',
            'computeAlternativeRoutes' => false,
            'routeModifiers' =>
                [
                    'avoidTolls' => false,
                    'avoidHighways' => false,
                    'avoidFerries' => false,
                ],
            'languageCode' => 'de-CH',
            'units' => 'METRIC',
            'headers' => [
                'X-Goog-FieldMask' => 'routes.duration,routes.distanceMeters',
            ],
        ];

        $geocodeResult = $gmaps->route($x, $y, $params);

from google-maps-services-php.

dereuromark avatar dereuromark commented on July 23, 2024

With #12 merged we can now close this.

from google-maps-services-php.

alex-kalanis avatar alex-kalanis commented on July 23, 2024

Okay. Although by the Google's own example of HTTP under combined with your settings:

curl -X POST -d '{
  "origin":{
    "location":{
      "latLng":{
        "latitude": 37.419734,
        "longitude": -122.0827784
      }
    }
  },
  "destination":{
    "location":{
      "latLng":{
        "latitude": 37.417670,
        "longitude": -122.079595
      }
    }
  },
  "travelMode": "DRIVE",
  "routingPreference": "TRAFFIC_AWARE",
  "computeAlternativeRoutes": false,
  "routeModifiers": {
    "avoidTolls": false,
    "avoidHighways": false,
    "avoidFerries": false
  },
  "languageCode": "de-CH",
  "units": "METRIC"
}' \
-H 'Content-Type: application/json' \
-H 'X-Goog-Api-Key: **YOUR_API_KEY**' \
-H 'X-Goog-FieldMask: routes.duration,routes.distanceMeters,routes.polyline.encodedPolyline' \
'https://routes.googleapis.com/directions/v2:computeRoutes'

then the possibility of usage the API key via GET param is undocumented one.

from google-maps-services-php.

dereuromark avatar dereuromark commented on July 23, 2024

We can definitly change the code to favor header :)

from google-maps-services-php.

dereuromark avatar dereuromark commented on July 23, 2024

aac9eec

from google-maps-services-php.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.