Skip to content

Instantly share code, notes, and snippets.

@fnzainal
Last active February 24, 2017 02:18
Show Gist options
  • Save fnzainal/be52691b7cfc20da15789cc7d6ef5648 to your computer and use it in GitHub Desktop.
Save fnzainal/be52691b7cfc20da15789cc7d6ef5648 to your computer and use it in GitHub Desktop.
untuk menghitung jarak di maps melalui jalan, bukan jarak lurus. Menggunakan api GoogleMaps

##URL FORMAT:

http://maps.googleapis.com/maps/api/directions/json?origin=" + lat1 + "," + lon1 + "&destination=" + lat2 + "," + lon2 + "&sensor=false&units=metric&mode=driving

##URL example:

http://maps.googleapis.com/maps/api/directions/json?origin=-7.0753592,110.3586899&destination=-7.1206129,110.4038428&sensor=false&units=metric&mode=driving

##JSON response with GET Request:

{
  "geocoded_waypoints": [
    {
      "geocoder_status": "OK",
      "place_id": "ChIJGXnICJSJcC4RfmCu-O0JBO8",
      "types": [
        "route"
      ]
    },
    {
      "geocoder_status": "OK",
      "place_id": "ChIJOaPByr-IcC4RXZadihqSCgk",
      "types": [
        "route"
      ]
    }
  ],
  "routes": [
    {
      "bounds": {
        "northeast": {
          "lat": -7.075258400000001,
          "lng": 110.4039605
        },
        "southwest": {
          "lat": -7.1206147,
          "lng": 110.3598489
        }
      },
      "copyrights": "Map data ©2017 Google",
      "legs": [
        {
          "distance": {
            "text": "8.1 km",
            "value": 8105
          },
          "duration": {
            "text": "15 mins",
            "value": 891
          },
          "end_address": "Jl. Hos. Cokroaminoto, Ungaran, Ungaran Bar., Semarang, Jawa Tengah 50511, Indonesia",
          "end_location": {
            "lat": -7.1206147,
            "lng": 110.4038661
          },
          "start_address": "Jl. Raya Manyaran-Gunungpati, Gunungpati, Gn. Pati, Kota Semarang, Jawa Tengah 50223, Indonesia",
          "start_location": {
            "lat": -7.075258400000001,
            "lng": 110.3598489
          },
          "steps": [
            {
              "distance": {
                "text": "1.4 km",
                "value": 1449
              },
              "duration": {
                "text": "3 mins",
                "value": 181
              },
              "end_location": {
                "lat": -7.0880065,
                "lng": 110.3620734
              },
              "html_instructions": "Head <b>south</b> on <b>Jl. Raya Manyaran-Gunungpati</b><div style=\"font-size:0.9em\">Pass by Masjid Alste (on the right in 350&nbsp;m)</div>",
              "polyline": {
                "points": "j{dj@atq`Tf@CVCRCdAUvAWJCHANAN?R?z@@^CN?VA`@C^C|@E|AKxB[xAIvBO|K_Ab@E^En@KVEbAMh@K\\Ex@Kd@G^El@El@Gp@Ed@AF?TANALALAPCLCLAHADCr@]l@YXKNGFAFCLCPE^GJAPAP?N?R@hBD"
              },
              "start_location": {
                "lat": -7.075258400000001,
                "lng": 110.3598489
              },
              "travel_mode": "DRIVING"
            },
            {
              "distance": {
                "text": "3.8 km",
                "value": 3846
              },
              "duration": {
                "text": "6 mins",
                "value": 374
              },
              "end_location": {
                "lat": -7.103171799999999,
                "lng": 110.3870539
              },
              "html_instructions": "Turn <b>left</b> onto <b>Jl. Raya Cangkiran-Gunungpati</b>/<b>Jl. Raya Gn. Pati</b><div style=\"font-size:0.9em\">Continue to follow Jl. Raya Gn. Pati</div>",
              "maneuver": "turn-left",
              "polyline": {
                "points": "`kgj@}ar`TIa@Ia@I_@I_@K_@GSGMIWACAA?CEGEIEIa@s@EIi@aAQ]g@aAq@oAS_@KUGSQk@Ii@CUCW?_@Ac@?iAHyD@}@FgA@MBMBOBKFSd@yAR{@F[BSDWB[FwBDqB?CNeE@Q@K@I@GBODOFMBKL]DKBMBKBO@QD]D_@BMBODGFIFIHIPKv@i@f@[VOLKNKJKLMNSLOLQJSTc@P_@N[Rc@N_@Tq@Xu@b@wAJWFMFKd@{@`BqCxAiCBEx@yABCJOFGh@m@XYX]DKJONYDKLWDEDCHGJGJELEPALAPA`@El@ERCdAGXAJ?L?R@n@FT@H@F?HAFAHCHCFEh@a@l@i@h@c@`@WNMb@a@n@]`@WLE^MRINEJCJEFAFCHEVOd@e@l@s@\\_@l@u@b@]TKTKZKZI|@QFC\\KZGBAXGNAf@CnAC^Ab@AN?z@HhANZ@J?NATGNEFCJI\\YvAmAx@u@PSV_@Nc@F]DUD]Fm@Dc@D[Hi@Ho@F]Z_AXo@"
              },
              "start_location": {
                "lat": -7.0880065,
                "lng": 110.3620734
              },
              "travel_mode": "DRIVING"
            },
            {
              "distance": {
                "text": "1.8 km",
                "value": 1769
              },
              "duration": {
                "text": "3 mins",
                "value": 188
              },
              "end_location": {
                "lat": -7.1131157,
                "lng": 110.3990572
              },
              "html_instructions": "Continue onto <b>Jl. Mr. Wurjanto</b>",
              "polyline": {
                "points": "xijj@a~v`TDIN[LQLONSTSTUVSb@]d@YZWpB{AHIdAu@b@]f@[^QdAc@LGLGJEJGHGNMXYdAqAv@oAh@{@NWTa@@GBGBKDM@G@I?C@G@Q@WD}@@S?C@K@M@OBK@M@ADODODOJU@AFKJSHQP_@N[DM@EVg@P]Tc@JM`B{BTa@NU~@oAd@q@tByCT]`ByBx@_AJM`@e@LONONKRQbA{@hAw@v@g@"
              },
              "start_location": {
                "lat": -7.103171799999999,
                "lng": 110.3870539
              },
              "travel_mode": "DRIVING"
            },
            {
              "distance": {
                "text": "0.9 km",
                "value": 939
              },
              "duration": {
                "text": "2 mins",
                "value": 134
              },
              "end_location": {
                "lat": -7.1197031,
                "lng": 110.4039475
              },
              "html_instructions": "Continue onto <b>Jl. Patimura</b>",
              "polyline": {
                "points": "~glj@ciy`TRMdBy@NGXODCp@_@PKfA{@DCrAo@RMVONMLKJIHMFI@CfB{Bp@}@jC}DRUTWj@c@DCh@a@?Az@c@JGx@g@ZM^IfAMLCLAl@Cl@@"
              },
              "start_location": {
                "lat": -7.1131157,
                "lng": 110.3990572
              },
              "travel_mode": "DRIVING"
            },
            {
              "distance": {
                "text": "0.1 km",
                "value": 102
              },
              "duration": {
                "text": "1 min",
                "value": 14
              },
              "end_location": {
                "lat": -7.1206147,
                "lng": 110.4038661
              },
              "html_instructions": "Continue onto <b>Jl. Hos. Cokroaminoto</b><div style=\"font-size:0.9em\">Destination will be on the right</div>",
              "polyline": {
                "points": "bqmj@ugz`TPBdADp@Bj@@"
              },
              "start_location": {
                "lat": -7.1197031,
                "lng": 110.4039475
              },
              "travel_mode": "DRIVING"
            }
          ],
          "traffic_speed_entry": [],
          "via_waypoint": []
        }
      ],
      "overview_polyline": {
        "points": "j{dj@atq`T~@GxAY|B_@b@?zAAhBIzCQxB[xAItOoAbAKtDk@|C_@zAMvAGz@Ez@KNE`Bw@x@YjASfA?hBDIa@SaAe@aBMa@}C{FeAoBSi@[uAGm@AcAHcGHeCD[t@iCZwAHk@PiGTmFRu@ZcANkAHm@HWNSZUdCaBZW\\a@|@yAdA_C~AwErHuMvA_B^i@Zi@Rc@JITOXKrAK`DSX?bAHp@@b@OvAkAjA{@r@o@pAu@pAc@f@O`@UrAyAjAuAb@]TKp@WxA[dAYh@IvBGbACjAHdBPZAd@MRMtBgBjAiAV_@Nc@Ls@XkCRyAF]Z_A^y@\\m@\\c@j@i@|BcBdFyDfAm@rAk@n@]h@g@dAqAv@oAx@sAVi@Ni@NuCHu@No@Zs@v@aBp@yA`@q@vB}CnAeBzCkEvBwCdAmAnAqAvAmA`C_BbD_Bv@c@xAgAdCqAr@q@bDgE~CsE`A{@n@e@z@e@dAo@z@WtAQz@EdCJ|AD"
      },
      "summary": "Jl. Raya Gn. Pati",
      "warnings": [],
      "waypoint_order": []
    }
  ],
  "status": "OK"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment