# how to get the center point between two lat and long points. • ### Question

• Hi all, can any one help me to get the center point between two lat and long. Im drawing a polyline between two cities i want to display a image exactly in the middle of the line. please can any one suggest how to accomplish this task in silverlight bing map.

raghu
• Moved by Friday, March 9, 2012 3:26 PM (From:Bing Maps: Map Control and Web services Development)
Monday, January 31, 2011 5:43 AM

### All replies

• Do you want the point that lies in the middle of those two cities on the surface of the Earth, or do you want the point that lies in the middle of the polyline drawn between those two cities on the map?

In other words, do you want Point A or B? Beginning Spatial with SQL Server http://www.apress.com/book/view/1430218290
Monday, January 31, 2011 1:44 PM
• Hi Tanoshimi,

i found the way how to find the mid point that lies in the middle of the two cities :

i did some thing like this :

var newlat = (lat1 + lat2 )/2;

var newlong = (lang1 + lang2)/2 ;

please correct me if im wrong and also could you please tell me how to accomplish point 'B'.

raghu
Tuesday, February 1, 2011 5:53 AM
• Windows Live Developer MVP - http://rbrundritt.spaces.live.com | http://inknowledge.co.uk
Tuesday, February 1, 2011 12:02 PM
• Hi Richard,

i went through the link you have suggested. and im doing like this in my code :

--------------------------------------------

Location newlocation = midpoint(latpush, longpush);
objPushpin.Location = newlocation;

-----------------------------------------------

private Location midpoint(Location latlong1, Location latlong2)
{
double arcLength = haversineDistance(latlong1, latlong2);
double brng = calculateBearing(latlong1, latlong2);
return calculateCoord(latlong1, brng, arcLength / 2);
}

private double haversineDistance(Location latlong1, Location latlong2)
{
var dLat = lat2 - lat1;
var dLon = lon2 - lon1;
var cordLength = Math.Pow(Math.Sin(dLat / 2), 2) + Math.Cos(lat1) * Math.Cos(lat2) * Math.Pow(Math.Sin(dLon / 2), 2);
var centralAngle = 2 * Math.Atan2(Math.Sqrt(cordLength), Math.Sqrt(1 - cordLength));
}

{
return x * Math.PI / 180;
}

{
return x * 180 / Math.PI;
}

private double calculateBearing(Location latlong1,Location latlong2)
{
var lon1 = latlong1.Longitude;
var lon2 = latlong2.Longitude;
var y = Math.Sin(dLon) * Math.Cos(lat2);
var x = Math.Cos(lat1)*Math.Sin(lat2) - Math.Sin(lat1)*Math.Cos(lat2)*Math.Cos(dLon);
return brng;
}

private Location calculateCoord(Location origin, double brng, double arcLength)
{
var centralAngle = arcLength / earthRadius;
var lat2 = Math.Asin(Math.Sin(lat1) * Math.Cos(centralAngle) + Math.Cos(lat1) * Math.Sin(centralAngle) * Math.Cos(DegtoRad(brng)));

var lon2 = lon1 + Math.Atan2(Math.Sin(DegtoRad(brng)) * Math.Sin(centralAngle) * Math.Cos(lat1), Math.Cos(centralAngle) - Math.Sin(lat1) * Math.Sin(lat2));

}

But its not display the pushpin in the appropriate where i wanted it to be displayed. Can any one please provide me some working code or a example how to accomplish Point 'B' or Point 'A' discussed in my earlier post.

raghu
Wednesday, February 2, 2011 2:32 AM
• Hi tanoshimi,

Could you please post a solution for Point 'B'. im trying to add a custom pushpin exactly between two cities. i tried what richard has posted but not able to get the approriate solution.

• 