Distance between two addresses

后端 未结 1 1833
暖寄归人
暖寄归人 2020-12-20 03:36

I\'m writing a booking web site in php and I would need a library or a remote service (similar to google maps api) that calculate the distance between 2 addresses.

I

1条回答
  •  没有蜡笔的小新
    2020-12-20 04:32

    Google Maps API - Directions is a good place to start.

    Sending off a request using the URL Pattern:

    http://maps.google.com/maps/api/directions/xml?origin=[FROM_ADDRESS]&destination=[TO_ADDRESS]&sensor=false
    // [FROM_ADDRESS] is a Google-Recognisable address for the Start
    // [TO_ADDRESS] is a Google-Recognisable address for the End
    

    Example - "How do I get to Carnegie Hall? (From Sony Music Entertainment)"

    Start Address: 550 Madison Avenue, New York, NY, United States End Address: 881 7th Avenue, New York, NY, United States

    The URL for the XML Directions from Google would be

    http://maps.google.com/maps/api/directions/xml?origin=550+Madison+Avenue,+New+York,+NY,+United+States&destination=881+7th+Avenue,+New+York,+NY,+United+States&sensor=false
    

    The result is:

    
      OK
      
        E 57th St
        
          
            DRIVING
            
              40.7612400
              -73.9731300
            
            
              40.7622900
              -73.9723600
            
            
              wdxwF`{nbMqEyC
              BB
            
            
              9
              1 min
            
            
              Head northeast on Madison Ave toward E 56th St
            
            
              133
              436 ft
            
          
          
            DRIVING
            
              40.7622900
              -73.9723600
            
            
              40.7655300
              -73.9800500
            
            
              ikxwFfvnbMgS`o@
              BB
            
            
              148
              2 mins
            
            
              Turn left at the 2nd cross street onto E 57th St
            
            
              741
              0.5 mi
            
          
          
            DRIVING
            
              40.7655300
              -73.9800500
            
            
              40.7651800
              -73.9803000
            
            
              q_ywFhfpbMdAp@
              BB
            
            
              39
              1 min
            
            
              Turn left at the 3rd cross street onto 7th Ave 
    Destination will be on the left
    45 148 ft
    196 3 mins 919 0.6 mi 40.7612400 -73.9731300 40.7651800 -73.9803000 550 Madison Ave, New York, NY 10022, USA 881 7th Ave, New York, NY 10019, USA
    Map data ©2010 Google, Sanborn wdxwF`{nbMqEyCgS`o@dAp@ B@?B

    So, the quickest route between those two points will have details of:

    • Duration in Seconds

      DirectionsResponse > route > leg > duration > value

    • Duration in Plain Text

      DirectionsResponse > route > leg > duration > text

    • Distance in Base Unit of Local Measurements (Feet or Metres)

      DirectionsResponse > route > leg > distance > value

    • Distance in Plain Text for Local Measurement (Miles or Kilometers)

      DirectionsResponse > route > leg > distance > text

    0 讨论(0)
提交回复
热议问题