public double CalculateDistanceOfNextStep(LatLng CurrentLocation, int index, DirectionStep step) { if (index >= step.PolyLineIndex) { return(0); } double d = 0; for (int i = index + 1; i < (step.PolyLineIndex); i++) { if (i + 1 < Points.Count) { d += util.GetDistanceBetweenPoints(Points[i], Points[i + 1]); } } d += util.GetDistanceBetweenPoints(CurrentLocation, Points[index + 1]); return(d); }
public DirectionStep GetDirectionNextStep(int PolyLineIndex) { if (PolyLineIndex < 0 || PolyLineIndex >= this.Points.Count) { return(null); } DirectionStep step = null; foreach (DirectionStep stp in this.Steps) { if (stp.PolyLineIndex > PolyLineIndex) { return(stp); } step = stp; } return(null); }
public string GetDirectionDiscriptionFromLocation(LatLng loc) { int index = GetNearestPolyIndex(loc); if (index < 0) { string Description = "You've lost your way!!!!"; if (!isLostWay) { #if SPEECH_ENABLED speaker.SpeakAsync(Description); #endif isLostWay = true; } return(Description); } else { DirectionStep step = GetDirectionNextStep(index); isLostWay = false; if (step != null) { double distance = CalculateDistanceOfNextStep(loc, index, step); string str_dis; if (distance < 1) { str_dis = " in " + String.Format("{0:0}", distance * 1000) + " Meters"; } else { str_dis = " in " + String.Format("{0:0.0}", distance) + " KiloMeters"; } string Description = step.step_description + str_dis; if (!step.far_speech) { #if SPEECH_ENABLED speaker.SpeakAsync(Description); #endif if (distance * 1000 < 300) { step.near_speech = true; } step.far_speech = true; } if (distance * 1000 < 300 && step.near_speech == false) { step.near_speech = true; #if SPEECH_ENABLED speaker.SpeakAsync(Description); #endif } return(Description); } else { isLostWay = true; double distance = util.GetDistanceBetweenPoints(loc, Points[Points.Count - 1]); string str_dis; if (distance < 1) { str_dis = "in " + String.Format("{0:0}", distance * 1000) + " Meters"; } else { str_dis = "in " + String.Format("{0:0.0}", distance) + " KiloMeters"; } string Description = "Arrive " + str_dis; if (distance * 1000 < 500) { if (!isArrived) { #if SPEECH_ENABLED speaker.SpeakAsync(Description); #endif } } isArrived = true; return(Description); } } }