1

My goal is to simply calculate a distance from point A to point B using IOS google maps SDK.

I found out that there is an API call Distance Matrix API. The questions are

  1. Do i need to make an HTTP request using Alamofire IOS to use Distance Matrix API?
  2. Do i need to run my own server (etc Node.js, django, rails) to make a request to the Distance matrix?

  3. Or everything is in IOS google maps SDK?

airsoftFreak
  • 1,450
  • 5
  • 34
  • 64

2 Answers2

3

1 -> Yes, you need to make a HTTP request.

2 -> No, you do not need to run your own server. You just need a google API key with which you make requests to Google servers. You can get the API key by creating a google account and following the instructions in the below link:- https://developers.google.com/maps/documentation/distance-matrix/start

3 -> You do not need to integrate the full iOS Google SDK if you need to perform only one of these tasks from the SDK. You can just hit the API following the instructions from the below doc Distance Matrix API doc:- https://developers.google.com/maps/documentation/distance-matrix/intro?hl=en#RequestParameters

Mohit
  • 126
  • 2
  • 10
7vikram7
  • 2,764
  • 1
  • 25
  • 43
  • Once I got the distance data in json format, how would I paste it on the map itself? – airsoftFreak May 25 '16 at 06:11
  • Once you get the distance, you can simply add a suitable annotation on the map indicating the distance. You can drop the annotation beside the route if you have plotted it. – 7vikram7 May 25 '16 at 06:14
  • Do you have any example, where I could follow? – airsoftFreak May 25 '16 at 06:39
  • http://stackoverflow.com/questions/15267183/custom-annotation-view-in-google-maps-sdk You can follow this link to add annotation if you are using google maps. – 7vikram7 May 25 '16 at 09:16
  • http://stackoverflow.com/questions/5491791/how-to-add-a-map-annotation-on-mkmapview You can use this link if you are using apple maps. Though these are in objective C the classes to be used are the same. Hope these and the answer helps. – 7vikram7 May 25 '16 at 09:17
0

Call the folowing URL, and it will return the distance between two lat longs. https://maps.googleapis.com/maps/api/distancematrix/json?origins=Vancouver+BC|Seattle&destinations=San+Francisco|Victoria+BC&key=YOUR_API_KEY

To get the API Key go to the google developer console and follow the steps:- Create or select a project. Click Continue to Enable the API. On the Credentials page, get a Server key (and set the API Credentials).

Following link has a demo related to the distance matrix :- https://developers.google.com/maps/documentation/distance-matrix/

Akshara
  • 141
  • 1
  • 11