2011-12-07 15 views
8

मुझे एक स्थान से दूसरे स्थान पर अनुमान ड्राइव समय खोजने की आवश्यकता है। मुझे दोनों जगहों के लिए अक्षांश और अक्षांश मिल गया है, लेकिन मुझे नहीं पता कि यह कैसे करना है। क्या इसके लिए कोई एपीआई है। धन्यवाद धन्यवाद।एंड्रॉइड - एक स्थान से दूसरे स्थान पर अनुमानित ड्राइव समय कैसे प्राप्त करें?

+0

क्यों नहीं गूगल मैप्स का उपयोग – Jeff

+0

मैं सिर्फ अनुमानित समय नहीं दिशाओं ... –

उत्तर

10

हाँ आपको समय और दूरी मूल्य के साथ-साथ ड्राइविंग, पैदल चलने आदि मोड में दिशा विवरण जैसे कई मिलते हैं। आप सभी गूगल दिशा एपीआई सेवा से मिला

जाँच हमारे इस लिंक

http://code.google.com/apis/maps/documentation/directions/

+0

सटीक जानकारी के लिए की जरूरत है + 1 –

+0

आपके उत्तर के लिए धन्यवाद। लेकिन यह जावास्क्रिप्ट के लिए है, मुझे एंड्रॉइड फोन एप्लिकेशन की आवश्यकता है .. –

+1

आप एंड्रॉइड में इस सेवा का उपयोग कर सकते हैं, आपको http पैकेज – Pratik

10
Location location1 = new Location(""); 
    location1.setLatitude(lat); 
    location1.setLongitude(long); 

    Location location2 = new Location(""); 
    location2.setLatitude(lat); 
    location2.setLongitude(long); 

    float distanceInMeters = location1.distanceTo(location2); 

संपादित:

//For example spead is 10 meters per minute. 
    int speedIs10MetersPerMinute = 10; 
    float estimatedDriveTimeInMinutes = distanceInMeters/speedIs10MetersPerMinute; 

भी इस, देखने के लिए कृपया नहीं काम करता है ऊपर यदि आप:

Calculate distance between two points in google maps V3

+0

मुझे लगता है कि यह समय वापस नहीं लौटाएगा –

+0

यह मीटर में दूरी लौटाएगा और यही कारण है कि मैंने लिखा "अब आपके पास दूरी INMeters है आप अनुमानित ड्राइव समय की गणना कर सकते हैं। " –

+0

क्या आप मुझे बता सकते हैं कि मुझे समय कैसे मिल सकता है? –

1

तुम भी उपयोग कर सकते हैं http://maps.google.com/maps?saddr= {START_ADDRESS} & daddr = {destination_address}

यह दोनों के बीच स्थानों

http://maps.google.com/maps?saddr=79.7189,72.3414&daddr=66.45,74.6333&ie=UTF8&0&om=0&output=kml

+0

आपके उत्तर के लिए धन्यवाद लेकिन मुझे दो स्थानों के बीच नेविगेट करने के लिए यूआरएल की आवश्यकता नहीं है। मुझे स्थानीय चर में अनुमानित यात्रा समय की आवश्यकता है ... –

-2
Calculate Distance:- 
    float distance; 
      Location locationA=new Location("A"); 
      locationA.setLatitude(lat); 
      locationA.setLongitude(lng); 

      Location locationB = new Location("B"); 
      locationB.setLatitude(lat); 
      locationB.setLongitude(lng); 

      distance = locationA.distanceTo(locationB)/1000; 

      LatLng From = new LatLng(lat,lng); 
      LatLng To = new LatLng(lat,lng); 

      Calculate Time:- 
      int speedIs1KmMinute = 100; 
      float estimatedDriveTimeInMinutes = distance/speedIs1KmMinute; 
       Toast.makeText(this,String.valueOf(distance+ 
"Km"),Toast.LENGTH_SHORT).show(); 
      Toast.makeText(this,String.valueOf(estimatedDriveTimeInMinutes+" Time"),Toast.LENGTH_SHORT).show(); 
में दूरी और समय के साथ साथ में दिशा विस्तार दे देंगे
+0

यह सड़कों को ध्यान में नहीं लेता है। उदाहरण के लिए, यह मुझे बताएगा कि मैं कैलिफोर्निया से हवाई तक ड्राइव कर सकता हूं। – Feathercrown

0

पहले से ही described by Praktik के रूप में, आप Google के दिशानिर्देश API का उपयोग करने के लिए आवश्यक समय का अनुमान लगाने के लिए उपयोग कर सकते हैं एक स्थान से दूसरे स्थान पर दिशा-निर्देश और यातायात लेना। लेकिन आपको वेब एपीआई का उपयोग करने और अपना खुद का रैपर बनाने की आवश्यकता नहीं है, इसके बजाय Google द्वारा प्रदत्त Java implementation का उपयोग करें, जो Maven/gradle भंडार के माध्यम से उपलब्ध है।

  1. Add the google-maps-services to your app's build.gradle:

    dependencies { 
        compile 'com.google.maps:google-maps-services:0.2.5' 
    } 
    
  2. अनुरोध को पूरा करें और अवधि निकालें:

    // - Put your api key (https://developers.google.com/maps/documentation/directions/get-api-key) here: 
    private static final String API_KEY = "AZ.." 
    
    /** 
    Use Google's directions api to calculate the estimated time needed to 
    drive from origin to destination by car. 
    
    @param origin The address/coordinates of the origin (see {@link DirectionsApiRequest#origin(String)} for more information on how to format the input) 
    @param destination The address/coordinates of the destination (see {@link DirectionsApiRequest#destination(String)} for more information on how to format the input) 
    
    @return The estimated time needed to travel human-friendly formatted 
    */ 
    public String getDurationForRoute(String origin, String destination) 
        // - We need a context to access the API 
        GeoApiContext geoApiContext = new GeoApiContext.Builder() 
         .apiKey(apiKey) 
         .build(); 
    
        // - Perform the actual request 
        DirectionsResult directionsResult = DirectionsApi.newRequest(geoApiContext) 
          .mode(TravelMode.DRIVING) 
          .origin(origin) 
          .destination(destination) 
          .await(); 
    
        // - Parse the result 
        DirectionsRoute route = directionsResult.routes[0]; 
        DirectionsLeg leg = route.legs[0]; 
        Duration duration = leg.duration; 
        return duration.humanReadable; 
    } 
    

सरलता के लिए, इस कोड को अपवाद त्रुटि मामलों को संभाल नहीं करता है (उदाहरण के लिए कोई मार्ग मिला -> मार्ग। लम्बाई == 0), और न ही यह route यासे अधिक परेशान करता है। मूल और गंतव्य भी LatLng उदाहरणों (DirectionsApiRequest#origin(LatLng) और DirectionsApiRequest#destination(LatLng) देखने के रूप में सीधे सेट किया जा सकता

अतिरिक्त पठन:।? android.jlelse.eu - Google Maps Directions API

संबंधित मुद्दे