# Routing not using closest point?

**URL:** <https://community.thinkgeo.com/t/routing-not-using-closest-point/7613>\
**Category:** Routing\
**Created:** [April 30, 2013, 9:25pm UTC](https://community.thinkgeo.com/t/routing-not-using-closest-point/7613 "2013-04-30T21:25:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Allen](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/a/bbce88/32.png) [@Allen](https://community.thinkgeo.com/u/Allen)\
**Post date:** [April 30, 2013, 9:25pm UTC](https://community.thinkgeo.com/t/routing-not-using-closest-point/7613/1 "2013-04-30T21:25:01Z")

</div>

Good&nbsp;evening,

In&nbsp;the&nbsp;picture&nbsp;below&nbsp;we&nbsp;are&nbsp;generating&nbsp;a&nbsp;route&nbsp;from&nbsp;the&nbsp;building&nbsp;marked&nbsp;with&nbsp;the&nbsp;pushpin&nbsp;to&nbsp;a&nbsp;point&nbsp;east&nbsp;on&nbsp;Marietta&nbsp;Avenue&nbsp;(to&nbsp;the&nbsp;lower&nbsp;right&nbsp;of&nbsp;the&nbsp;picture's&nbsp;coverage&nbsp;area).&nbsp;&nbsp;Based&nbsp;on&nbsp;measurement&nbsp;lines&nbsp;drawn&nbsp;by&nbsp;our&nbsp;application,&nbsp;it&nbsp;appears&nbsp;that&nbsp;the&nbsp;road&nbsp;closest&nbsp;to&nbsp;the&nbsp;point&nbsp;is&nbsp;not&nbsp;being&nbsp;selected&nbsp;as&nbsp;the&nbsp;starting&nbsp;point&nbsp;and&nbsp;the&nbsp;route&nbsp;is&nbsp;starting&nbsp;on&nbsp;Route&nbsp;30&nbsp;W&nbsp;instead&nbsp;of&nbsp;Marietta&nbsp;Avenue,&nbsp;although&nbsp;Marietta&nbsp;Avenue&nbsp;is&nbsp;more&nbsp;than&nbsp;60&nbsp;feet&nbsp;closer.&nbsp;&nbsp;Instead&nbsp;of&nbsp;generating&nbsp;a&nbsp;route&nbsp;that&nbsp;should&nbsp;go&nbsp;a&nbsp;few&nbsp;blocks&nbsp;it&nbsp;generates&nbsp;a&nbsp;route&nbsp;that&nbsp;goes&nbsp;out&nbsp;onto&nbsp;a&nbsp;highway,&nbsp;finds&nbsp;a&nbsp;ramp,&nbsp;goes&nbsp;onto&nbsp;the&nbsp;eastbound&nbsp;lane,&nbsp;and&nbsp;comes&nbsp;back&nbsp;onto&nbsp;Marietta&nbsp;Avenue&nbsp;via&nbsp;a&nbsp;road&nbsp;to&nbsp;the&nbsp;north,&nbsp;etc.&nbsp;&nbsp;The&nbsp;bottom&nbsp;picture&nbsp;shows&nbsp;the&nbsp;same&nbsp;area&nbsp;in&nbsp;the&nbsp;routing&nbsp;shapefile.&nbsp;&nbsp;Note&nbsp;that&nbsp;Marietta&nbsp;Avenue&nbsp;is&nbsp;also&nbsp;Route&nbsp;23.

Any&nbsp;idea&nbsp;what's&nbsp;going&nbsp;on&nbsp;here?&nbsp;&nbsp;The&nbsp;one&nbsp;thing&nbsp;that&nbsp;occurs&nbsp;to&nbsp;me&nbsp;is&nbsp;that&nbsp;the&nbsp;closest&nbsp;point&nbsp;of&nbsp;the&nbsp;road&nbsp;segment&nbsp;to&nbsp;the&nbsp;starting&nbsp;point&nbsp;is&nbsp;not&nbsp;being&nbsp;used,&nbsp;but&nbsp;perhaps&nbsp;some&nbsp;other&nbsp;point&nbsp;of&nbsp;the&nbsp;segment.

Thanks,

Allen

&nbsp;

 ![](https://community.thinkgeo.com/uploads/default/original/2X/f/f47b189a68fbe9e06d3529b03d597f1a282b4bf7.png)

 ![](https://community.thinkgeo.com/uploads/default/original/2X/c/c8469b853e629f080bc6bd99ba37e464498e89ac.png)

---

<div class="post-metadata">

**Author:** ![Johnny](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/johnny/32/19044_2.png) [@Johnny](https://community.thinkgeo.com/u/Johnny)\
**Post date:** [May 2, 2013, 9:19am UTC](https://community.thinkgeo.com/t/routing-not-using-closest-point/7613/2 "2013-05-02T09:19:53Z")

</div>

&nbsp;

Hi&nbsp;Allen,  
Thanks&nbsp;for&nbsp;your&nbsp;post&nbsp;and&nbsp;detailed&nbsp;description.  
To&nbsp;make&nbsp;sure&nbsp;I&nbsp;understand&nbsp;you&nbsp;clearly,&nbsp;please&nbsp;allow&nbsp;me&nbsp;to&nbsp;confirm&nbsp;how&nbsp;you&nbsp;get&nbsp;the&nbsp;closest&nbsp;point?&nbsp;Are&nbsp;you&nbsp;trying&nbsp;the&nbsp;steps&nbsp;as&nbsp;following:  
1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get&nbsp;the&nbsp;nearest&nbsp;feature(road)&nbsp;with&nbsp;method&nbsp;like&nbsp;“featureSource.GetFeaturesNearestTo”.  
2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get&nbsp;the&nbsp;closest&nbsp;point&nbsp;on&nbsp;the&nbsp;feature&nbsp;as&nbsp;the&nbsp;routing&nbsp;start&nbsp;point&nbsp;with&nbsp;method&nbsp;like&nbsp;“nearestFeatureLine.GetClosestPointTo(currentMousePosition,&nbsp;winformsMap1.MapUnit);”.  
&nbsp;  
If&nbsp;yes,&nbsp;there&nbsp;might&nbsp;be&nbsp;a&nbsp;bug&nbsp;in&nbsp;the&nbsp;method&nbsp;“GetFeaturesNearestTo”&nbsp;and&nbsp;now,&nbsp;we&nbsp;are&nbsp;working&nbsp;on&nbsp;it,&nbsp;now&nbsp;can&nbsp;you&nbsp;try&nbsp;the&nbsp;workaround&nbsp;as&nbsp;following:

`            double minDistance = double.MaxValue;            Feature nearestFeature = null;            Collection<Feature> possibleNearestFeatures = featureSource.GetFeaturesNearestTo(pushpinPosition, winformsMap1.MapUnit, 1, new string[] {});            foreach (var item in possibleNearestFeatures)            {                LineBaseShape line = item.GetShape() as LineBaseShape;                double currentDistance = line.GetDistanceTo(currentMousePosition, winformsMap1.MapUnit, DistanceUnit.Meter);                if (currentDistance < minDistance)                {                    minDistance = currentDistance;                    nearestFeature = item;                }            }            if (nearestFeature != null)            {                LineBaseShape line = nearestFeature.GetShape() as LineBaseShape;                closestPoint = line.GetClosestPointTo(pushpinPosition, winformsMap1.MapUnit);            }`

From&nbsp;the&nbsp;code&nbsp;above,&nbsp;we&nbsp;know&nbsp;we&nbsp;still&nbsp;use&nbsp;the&nbsp;method&nbsp;“featureSource.GetFeaturesNearestTo”&nbsp;to&nbsp;get&nbsp;the&nbsp;“optional”&nbsp;nearest&nbsp;features,&nbsp;but&nbsp;do&nbsp;a&nbsp;minor&nbsp;changes&nbsp;here,&nbsp;maybe&nbsp;you&nbsp;have&nbsp;noticed&nbsp;there&nbsp;is&nbsp;a&nbsp;input&nbsp;parameter&nbsp;“maxItemsToFind”&nbsp;for&nbsp;this&nbsp;method,&nbsp;now&nbsp;we&nbsp;can&nbsp;assign&nbsp;it&nbsp;as&nbsp;like&nbsp;3,&nbsp;Which&nbsp;means&nbsp;we&nbsp;might&nbsp;get&nbsp;at&nbsp;most&nbsp;3&nbsp;nearest&nbsp;features&nbsp;on&nbsp;this&nbsp;point.  
If&nbsp;we&nbsp;fixed&nbsp;this&nbsp;bug,&nbsp;we&nbsp;will&nbsp;update&nbsp;the&nbsp;status&nbsp;here&nbsp;as&nbsp;soon&nbsp;as&nbsp;possible.  
Sorry&nbsp;for&nbsp;any&nbsp;inconvenient.  
Best&nbsp;regards  
Johnny

---

<div class="post-metadata">

**Author:** ![Allen](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/a/bbce88/32.png) [@Allen](https://community.thinkgeo.com/u/Allen)\
**Post date:** [May 2, 2013, 10:10am UTC](https://community.thinkgeo.com/t/routing-not-using-closest-point/7613/3 "2013-05-02T10:10:08Z")

</div>

Good&nbsp;afternoon&nbsp;Johnny,&nbsp;  
&nbsp;&nbsp;  
&nbsp;It’s&nbsp;actually&nbsp;much&nbsp;simplier&nbsp;than&nbsp;that.&nbsp;&nbsp;The&nbsp;user&nbsp;right-clicks&nbsp;on&nbsp;the&nbsp;map&nbsp;and&nbsp;a&nbsp;contextual&nbsp;menu&nbsp;comes&nbsp;up&nbsp;with&nbsp;an&nbsp;option&nbsp;to&nbsp;plot&nbsp;a&nbsp;“call&nbsp;point”.&nbsp;&nbsp;This&nbsp;is&nbsp;the&nbsp;yellow&nbsp;pushpin&nbsp;on&nbsp;the&nbsp;map&nbsp;above.&nbsp;&nbsp;The&nbsp;user&nbsp;then&nbsp;right-clicks&nbsp;on&nbsp;the&nbsp;map&nbsp;again&nbsp;and&nbsp;selects&nbsp;the&nbsp;“start&nbsp;route&nbsp;here”&nbsp;menu&nbsp;option.&nbsp;&nbsp;So&nbsp;we&nbsp;are&nbsp;passing&nbsp;the&nbsp;two&nbsp;points&nbsp;into&nbsp;the&nbsp;routing&nbsp;engine,&nbsp;and,&nbsp;presumably,&nbsp;letting&nbsp;it&nbsp;find&nbsp;the&nbsp;closest&nbsp;road&nbsp;segments.&nbsp;&nbsp;MOST&nbsp;OF&nbsp;THE&nbsp;TIME&nbsp;this&nbsp;works&nbsp;properly,&nbsp;but&nbsp;in&nbsp;the&nbsp;case&nbsp;above&nbsp;the&nbsp;routing&nbsp;engine&nbsp;seems&nbsp;to&nbsp;prefer&nbsp;the&nbsp;highway&nbsp;over&nbsp;the&nbsp;local&nbsp;road&nbsp;(even&nbsp;though&nbsp;the&nbsp;local&nbsp;road&nbsp;is&nbsp;closer)&nbsp;as&nbsp;the&nbsp;ending&nbsp;point&nbsp;(at&nbsp;the&nbsp;building&nbsp;with&nbsp;the&nbsp;pushpin),&nbsp;but&nbsp;there&nbsp;is&nbsp;no&nbsp;nearby&nbsp;access&nbsp;to&nbsp;the&nbsp;highway&nbsp;at&nbsp;that&nbsp;point.&nbsp;There&nbsp;has&nbsp;been&nbsp;some&nbsp;speculation&nbsp;in&nbsp;the&nbsp;office&nbsp;that&nbsp;the&nbsp;routing&nbsp;engine&nbsp;may&nbsp;prefer&nbsp;highways&nbsp;(using&nbsp;the&nbsp;segment&nbsp;weight)&nbsp;over&nbsp;local&nbsp;roads,&nbsp;but&nbsp;I&nbsp;have&nbsp;no&nbsp;way&nbsp;of&nbsp;knowing&nbsp;that.&nbsp;  
&nbsp;&nbsp;  
&nbsp;To&nbsp;get&nbsp;around&nbsp;this&nbsp;to&nbsp;some&nbsp;degree,&nbsp;we&nbsp;have&nbsp;extended&nbsp;our&nbsp;logic&nbsp;to&nbsp;look&nbsp;at&nbsp;the&nbsp;roads&nbsp;at&nbsp;the&nbsp;start&nbsp;and&nbsp;end&nbsp;of&nbsp;the&nbsp;route&nbsp;and&nbsp;only&nbsp;use&nbsp;a&nbsp;highway&nbsp;or&nbsp;ramp&nbsp;if&nbsp;it’s&nbsp;within&nbsp;10&nbsp;meters&nbsp;of&nbsp;the&nbsp;point,&nbsp;giving&nbsp;preference&nbsp;to&nbsp;local&nbsp;roads&nbsp;which&nbsp;would&nbsp;be&nbsp;actual&nbsp;access&nbsp;points&nbsp;to&nbsp;the&nbsp;route.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Allen

---

<div class="post-metadata">

**Author:** ![Johnny](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/johnny/32/19044_2.png) [@Johnny](https://community.thinkgeo.com/u/Johnny)\
**Post date:** [May 3, 2013, 5:32am UTC](https://community.thinkgeo.com/t/routing-not-using-closest-point/7613/4 "2013-05-03T05:32:02Z")

</div>

&nbsp;Hi&nbsp;Allen,&nbsp;

Do&nbsp;you&nbsp;mean&nbsp;the&nbsp;two&nbsp;points&nbsp;for&nbsp;routing&nbsp;engine&nbsp;are&nbsp;the&nbsp;location&nbsp;where&nbsp;the&nbsp;user&nbsp;right-click&nbsp;on?&nbsp;Also,&nbsp;you&nbsp;didn’t&nbsp;get&nbsp;the&nbsp;closest&nbsp;point&nbsp;on&nbsp;the&nbsp;road&nbsp;and&nbsp;let&nbsp;it&nbsp;as&nbsp;the&nbsp;routing&nbsp;engine&nbsp;start/end&nbsp;point?&nbsp;

If&nbsp;it&nbsp;is,&nbsp;I&nbsp;guess&nbsp;it&nbsp;is&nbsp;caused&nbsp;by&nbsp;the&nbsp;same&nbsp;reason&nbsp;above,&nbsp;as&nbsp;routing&nbsp;engine&nbsp;find&nbsp;a&nbsp;wrong&nbsp;closest&nbsp;point&nbsp;on&nbsp;the&nbsp;road&nbsp;from&nbsp;the&nbsp;user&nbsp;click&nbsp;position.&nbsp;So,&nbsp;we&nbsp;need&nbsp;to&nbsp;do&nbsp;pre-work&nbsp;to&nbsp;set&nbsp;the&nbsp;start&nbsp;point&nbsp;and&nbsp;end&nbsp;point&nbsp;before&nbsp;we&nbsp;fixed&nbsp;the&nbsp;bug.&nbsp;A&nbsp;little&nbsp;work&nbsp;is&nbsp;like&nbsp;I&nbsp;mentioned&nbsp;before,&nbsp;we&nbsp;need&nbsp;to&nbsp;get&nbsp;the&nbsp;closest&nbsp;point&nbsp;on&nbsp;the&nbsp;road&nbsp;from&nbsp;the&nbsp;position&nbsp;where&nbsp;user&nbsp;click.

` Double maxItemsToFind = 3;double minDistance = double.MaxValue;            Feature nearestFeature = null;            Collection<Feature> possibleNearestFeatures = featureSource.GetFeaturesNearestTo(pushpinPosition, winformsMap1.MapUnit, maxItemsToFind, new string[] {});            foreach (var item in possibleNearestFeatures)            {                LineBaseShape line = item.GetShape() as LineBaseShape;                double currentDistance = line.GetDistanceTo(pushpinPosition, winformsMap1.MapUnit, DistanceUnit.Meter);                if (currentDistance < minDistance)                {                    minDistance = currentDistance;                    nearestFeature = item;                }            }            if (nearestFeature != null)            {                LineBaseShape line = nearestFeature.GetShape() as LineBaseShape;                closestPoint = line.GetClosestPointTo(pushpinPosition, winformsMap1.MapUnit);            } `

Please&nbsp;follow&nbsp;the&nbsp;above&nbsp;workaround&nbsp;and&nbsp;have&nbsp;a&nbsp;try.

Thanks,

Johnny

---

<div class="post-metadata">

**Author:** ![Allen](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/a/bbce88/32.png) [@Allen](https://community.thinkgeo.com/u/Allen)\
**Post date:** [May 3, 2013, 7:27am UTC](https://community.thinkgeo.com/t/routing-not-using-closest-point/7613/5 "2013-05-03T07:27:09Z")

</div>

Hi&nbsp;Johnny,&nbsp;  
&nbsp;&nbsp;  
&nbsp;I&nbsp;may&nbsp;be&nbsp;mistaken&nbsp;here…for&nbsp;some&nbsp;reason&nbsp;I&nbsp;thought&nbsp;when&nbsp;I&nbsp;fed&nbsp;two&nbsp;points&nbsp;into&nbsp;the&nbsp;routing&nbsp;engine&nbsp;that&nbsp;I&nbsp;had&nbsp;read&nbsp;that&nbsp;it&nbsp;would&nbsp;find&nbsp;the&nbsp;closest&nbsp;road&nbsp;segments&nbsp;to&nbsp;the&nbsp;starting&nbsp;and&nbsp;ending&nbsp;points,&nbsp;but&nbsp;I&nbsp;can’t&nbsp;find&nbsp;anything&nbsp;documenting&nbsp;that&nbsp;at&nbsp;the&nbsp;moment.&nbsp;&nbsp;If&nbsp;it’s&nbsp;supposed&nbsp;to&nbsp;do&nbsp;that&nbsp;then&nbsp;this&nbsp;might&nbsp;be&nbsp;a&nbsp;bug,&nbsp;but&nbsp;if&nbsp;it’s&nbsp;not&nbsp;supposed&nbsp;to&nbsp;do&nbsp;that,&nbsp;then&nbsp;I&nbsp;agree&nbsp;100%&nbsp;with&nbsp;what&nbsp;you&nbsp;said&nbsp;and&nbsp;we&nbsp;can&nbsp;forget&nbsp;the&nbsp;whole&nbsp;thing!&nbsp;  
&nbsp;&nbsp;  
&nbsp;Anyway,&nbsp;as&nbsp;I&nbsp;noted&nbsp;above,&nbsp;I&nbsp;have&nbsp;implemented&nbsp;something&nbsp;like&nbsp;you&nbsp;suggest:&nbsp;I&nbsp;get&nbsp;the&nbsp;10&nbsp;closest&nbsp;roads&nbsp;to&nbsp;both&nbsp;the&nbsp;starting&nbsp;and&nbsp;ending&nbsp;points&nbsp;and&nbsp;scan&nbsp;them,&nbsp;giving&nbsp;local&nbsp;roads&nbsp;more&nbsp;priority&nbsp;over&nbsp;highways&nbsp;and&nbsp;ramps&nbsp;to&nbsp;avoid&nbsp;the&nbsp;situation&nbsp;like&nbsp;I&nbsp;show&nbsp;in&nbsp;the&nbsp;picture:&nbsp;only&nbsp;if&nbsp;a&nbsp;ramp&nbsp;or&nbsp;highway&nbsp;is&nbsp;within&nbsp;10&nbsp;meters&nbsp;is&nbsp;it&nbsp;used.&nbsp;&nbsp;The&nbsp;result&nbsp;is&nbsp;that&nbsp;the&nbsp;ending&nbsp;point&nbsp;(near&nbsp;the&nbsp;yellow&nbsp;pushpin)&nbsp;is&nbsp;placed&nbsp;on&nbsp;Marietta&nbsp;Avenue&nbsp;instead&nbsp;of&nbsp;the&nbsp;middle&nbsp;of&nbsp;a&nbsp;highway&nbsp;that&nbsp;can’t&nbsp;be&nbsp;accessed&nbsp;without&nbsp;driving&nbsp;miles&nbsp;to&nbsp;a&nbsp;ramp.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Allen

---

<div class="post-metadata">

**Author:** ![Johnny](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/johnny/32/19044_2.png) [@Johnny](https://community.thinkgeo.com/u/Johnny)\
**Post date:** [May 6, 2013, 9:23am UTC](https://community.thinkgeo.com/t/routing-not-using-closest-point/7613/6 "2013-05-06T09:23:58Z")

</div>

&nbsp;Hi&nbsp;Allen,

I&nbsp;think&nbsp;you&nbsp;were&nbsp;correct,&nbsp;it&nbsp;should&nbsp;be&nbsp;a&nbsp;bug&nbsp;here,&nbsp;what&nbsp;we&nbsp;expected&nbsp;is&nbsp;what&nbsp;you&nbsp;did&nbsp;for&nbsp;the&nbsp;first&nbsp;time.&nbsp;we&nbsp;are&nbsp;still&nbsp;working&nbsp;on&nbsp;it&nbsp;now,&nbsp;I&nbsp;will&nbsp;try&nbsp;getting&nbsp;the&nbsp;fix&nbsp;ASAP&nbsp;and&nbsp;let&nbsp;you&nbsp;know&nbsp;here.

For&nbsp;the&nbsp;problem&nbsp;shown&nbsp;in&nbsp;the&nbsp;picture&nbsp;you&nbsp;provided,&nbsp;I&nbsp;don’t&nbsp;think&nbsp;it&nbsp;is&nbsp;caused&nbsp;by&nbsp;the&nbsp;priority&nbsp;between&nbsp;highways&nbsp;and&nbsp;ramps.&nbsp;It&nbsp;is&nbsp;still&nbsp;caused&nbsp;by&nbsp;this&nbsp;bug.&nbsp;So,&nbsp;I&nbsp;guess&nbsp;you&nbsp;can&nbsp;try&nbsp;removing&nbsp;code&nbsp;for&nbsp;checking&nbsp;the&nbsp;priority.

Sorry&nbsp;for&nbsp;the&nbsp;inconvenience.

&nbsp;

Best&nbsp;regards,

Johnny

---

<div class="post-metadata">

**Author:** ![Johnny](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/johnny/32/19044_2.png) [@Johnny](https://community.thinkgeo.com/u/Johnny)\
**Post date:** [May 9, 2013, 7:43am UTC](https://community.thinkgeo.com/t/routing-not-using-closest-point/7613/7 "2013-05-09T07:43:18Z")

</div>

Hi&nbsp;Allen,&nbsp;  
&nbsp;&nbsp;  
&nbsp;We&nbsp;have&nbsp;fixed&nbsp;the&nbsp;bug,&nbsp;would&nbsp;you&nbsp;please&nbsp;download&nbsp;the&nbsp;latest&nbsp;version&nbsp;6.0.361.0&nbsp;or&nbsp;6.0.0.361&nbsp;and&nbsp;try&nbsp;it&nbsp;again?&nbsp;  
&nbsp;&nbsp;  
&nbsp;Hope&nbsp;it&nbsp;helps&nbsp;  
&nbsp;&nbsp;  
&nbsp;Johnny&nbsp;
