Reputation: 1260
I would like calculator distance between 2 coordinates using GMap API. I'm looking for anyway to catch return data from URL
https://maps.googleapis.com/maps/api/distancematrix/json?origins=Seattle&destinations=San+Francisco&key={{myKey}}
I tried to searching but no any thing I purpose. Please help me or give me keywords. Thanks a lot!
Upvotes: 2
Views: 966
Reputation: 116
You can use the super awesome request package
From it's documentation:
Request is designed to be the simplest way possible to make http calls. It supports HTTPS and follows redirects by default.
var request = require('request');
request('http://www.google.com', function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body) // Show the HTML for the Google homepage.
}
})
Hope that helps!
Upvotes: 3
Reputation: 977
Google's own API documentation should contain everything you need:
https://developers.google.com/maps/documentation/javascript/distancematrix
First geocode your origin and destination from cities (or whatever) to LatLng objects:
Geocoding is the process of converting addresses (like "1600 Amphitheatre Parkway, Mountain View, CA") into geographic coordinates (like latitude 37.423021 and longitude -122.083739), which you can use to place markers on a map, or position the map.
https://developers.google.com/maps/documentation/geocoding/intro
Using the LatLng objects you get in response, call Distance Matrix Service.
Upvotes: 2