4

I have two text-boxes in which user enters his source and destination, when user presses submit button one marker is drawn at source and other one is drawn at destination so can any one tell me how to find the mid locations? Using google map api version3.

Jakub Hampl
  • 39,863
  • 10
  • 77
  • 106
awais abbasi
  • 41
  • 1
  • 2
  • 1
    Do you want to find the middle location on the route (the road direction) between the given points; or the middle location of the polyline if you just connect these two points? – GoG Mar 21 '11 at 21:29
  • Thanks @GoG. I assumed directions, but OP may well mean mid point. In any case we have both answers here ;) – RedBlueThing Mar 21 '11 at 22:52
  • i watn to get full cordinate of polyline mean to encode the polyline – awais abbasi May 25 '11 at 17:20

2 Answers2

0

You can do a directions request between the two points. This will render a polyline on the map for the driving directions between the two points.

RedBlueThing
  • 42,006
  • 17
  • 96
  • 122
  • To get the directions in .NET you can use this open source project - code.google.com/p/google-maps/ – Maxim May 21 '11 at 21:55
0

Just do a little bit of math. You basically want to find the midpoint of two points on a line, following this formula:

x1 + x2
-------
   2

You'll want to do this twice, once for latitude and once for longitude. Then you can place a marker on your map.

Jess
  • 42,368
  • 6
  • 37
  • 51
  • but don't forget to make sure that |x1-x2-n*2*pi| <= pi. (Imagine x1=1deg, x2=359deg, you don't want 180deg as midpoint but rather 0 deg) – Philipp Mar 21 '11 at 20:17
  • @Philipp Yes, that is true. I meant to put in a disclaimer that this probably would require more work if you're wrapping around the map. – Jess Mar 21 '11 at 20:19
  • Even if you're not wrapping around the map, note that this will get the midpoint between the two locations, as projected onto a flat map, and will be inaccurate for long distances. For example, LA to London should go north, over Greenland, but the simple midpoint will end up being off the coast of Maine. See http://www.gcmap.com/mapui?P=LHR-LAX for what the great circle route would look like. – David Yaw Mar 21 '11 at 21:31