5

एक छोटी अवधि के दौरान एक चलती डिवाइस के रीयलटाइम स्थान डेटा को देखते हुए, मैं इस सड़क के साथ एक लेट/लम्बी जोड़ी आगे कैसे प्राप्त कर सकता हूं, कहें, 2 मील या इससे भी बेहतर, 5 मिनट के ड्राइविंग के लायक?मैं सड़क के साथ आगे कैसे फैल सकता हूं?

मुझे लगता है कि मैं लेट/लम्बी जोड़ी https://developers.google.com/maps/documentation/roads/snap दिए गए सड़क पर स्नैप करने के लिए Google की सड़क एपीआई का उपयोग कर सकता हूं, लेकिन यह केवल मुझे वहां भाग लेता है।

यह एक एंड्रॉइड ऐप में होगा।

+0

नहीं गूगल दिशाओं एपीआई कि के लिए समाधान के कुछ प्रकार है https करता है: //developers.google.com/maps/documentation/directions/intro#Waypoints – commonSenseCode

+0

ऐसा नहीं है कि मैं – Ken

+0

देख सकता हूं, मुझे लगता है कि आप इस https://developer.android.com/reference/android/telephony/TelephonyManager.html#getCellLocation() –

उत्तर

5

एक मार्ग एक List<LatLng> के रूप में प्रतिनिधित्व को देखते हुए, इस समारोह मार्ग कि उस मार्ग पर origin से distance मीटर यात्रा का परिणाम है पर बिंदु की गणना करता है (Google Maps API Utility Library का उपयोग कर कुछ गणना करने के लिए):

private LatLng extrapolate(List<LatLng> path, LatLng origin, float distance) { 
    LatLng extrapolated = null; 

    if (!PolyUtil.isLocationOnPath(origin, path, false, 1)) { // If the location is not on path non geodesic, 1 meter tolerance 
     return null; 
    } 

    float accDistance = 0f; 
    boolean foundStart = false; 
    List<LatLng> segment = new ArrayList<>(); 

    for (int i = 0; i < path.size() - 1; i++) { 
     LatLng segmentStart = path.get(i); 
     LatLng segmentEnd = path.get(i + 1); 

     segment.clear(); 
     segment.add(segmentStart); 
     segment.add(segmentEnd); 

     double currentDistance = 0d; 

     if (!foundStart) { 
      if (PolyUtil.isLocationOnPath(origin, segment, false, 1)) { 
       foundStart = true; 

       currentDistance = SphericalUtil.computeDistanceBetween(origin, segmentEnd); 

       if (currentDistance > distance) { 
        double heading = SphericalUtil.computeHeading(origin, segmentEnd); 
        extrapolated = SphericalUtil.computeOffset(origin, distance - accDistance, heading); 
        break; 
       } 
      } 
     } else { 
      currentDistance = SphericalUtil.computeDistanceBetween(segmentStart, segmentEnd); 

      if (currentDistance + accDistance > distance) { 
       double heading = SphericalUtil.computeHeading(segmentStart, segmentEnd); 
       extrapolated = SphericalUtil.computeOffset(segmentStart, distance - accDistance, heading); 
       break; 
      } 
     } 

     accDistance += currentDistance; 
    } 

    return extrapolated; 
} 

यहाँ कुछ परीक्षण:

List<LatLng> route = new ArrayList<>(); 
route.add(new LatLng(40, 4)); 
route.add(new LatLng(40.1, 4)); 
route.add(new LatLng(40.1, 4.1)); 
route.add(new LatLng(40.2, 4.1)); 
route.add(new LatLng(40.2, 4.2)); 
route.add(new LatLng(40.3, 4.2)); 
route.add(new LatLng(40.3, 4.3)); 

LatLng origin; 
LatLng extrapolated; 

origin = new LatLng(40.1, 4.05); 
extrapolated = extrapolate(route, origin, 30000); 
Log.e("Extrapolated1", "" + extrapolated); // lat/lng: (40.25517043951189,4.2) 

origin = new LatLng(40.05, 4); 
extrapolated = extrapolate(route, origin, 100); 
Log.e("Extrapolated2", "" + extrapolated); // lat/lng: (40.05089932033549,4.0) 

origin = new LatLng(40.05, 4); 
extrapolated = extrapolate(route, origin, 50000); 
Log.e("Extrapolated3", "" + extrapolated); // lat/lng: (40.300010207449226,4.261348349980259) 

origin = new LatLng(40.05, 4); 
extrapolated = extrapolate(route, origin, 100000); 
Log.e("Extrapolated4", "" + extrapolated); // null (result out of the route) 
+0

शानदार उत्तर की तलाश में हैं! दुर्भाग्य से, मेरे पास कोई रास्ता नहीं है। मैंने इसे स्पष्ट करने के लिए प्रश्न संपादित किया है। – Ken

+1

अगर मुझे आपकी ज़रूरतों के मुताबिक कुछ मिलता है तो मैं अपना जवाब संपादित करूंगा, लेकिन अगर मैं आपके बारे में दूसरों की मदद नहीं कर सकता तो मैं इस विधि को रखूंगा – antonio

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