Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have Latitude 28.6368897, Longitude 77.0694746 and i want to find next Latitude & Longitude in 2 kilometer.? in c#

I have code in Java script,


XML
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&libraries=geometry"></script>
<script>
function Distance(){
//debugger;
var p1 = new google.maps.LatLng(28.6368897, 77.0694746);
var p2 = new google.maps.LatLng(28.6361000, 77.0691000);

alert(calcDistance(p1, p2));
}
//calculates distance between two points in km's
function calcDistance(p1, p2){
  return (google.maps.geometry.spherical.computeDistanceBetween(p1, p2) / 1000).toFixed(2);
}


can any one convert into c#
Posted
Updated 27-Jan-15 4:18am
v4
Comments
BillWoodruff 27-Jan-15 3:07am    
"in two kilometers" could mean anywhere on the circumference of a circle whose radius was 2 kilometers ... unless you specify a direction.
janmejay1 27-Jan-15 4:07am    
yes anywhere on the circumference of a circle whose radius was 2 kilometers
Tomas Takac 27-Jan-15 5:17am    
In theory there is infinite number of such points do you realize that? Furthermore your code in javascript just calculates distance between two points. So what is the question: convert the javascript code to C# or a unrelated C# code to get you a (random?) point 2km from the original location?
V. 27-Jan-15 6:52am    
if longitude,latitude are x and y you could calculate the radius with r = sqrt(power(long, 2) + power(lat, 2)). using the knowledge that r has to be 2 you can reverse calculate the longitude if you have the laitude or vice versa.

However a small note, the earth is not flat and this formula only gives a 2d solution. If you want to use the "real" distance (on the sphere) you'll need to deproject it, which is not a trivial task.

Hope this helps.
Philippe Mori 27-Jan-15 13:01pm    
Well, it depends on how much precision you need. If you need only a rough approximation, then High school mathematics might be enough otherwise you might need to find/buy a library that does that. There are many mapping that approximate the earth surface some of which are optimized for some regions or for some other criteria like lines, distances...

1 solution

It doesn't quite work like that.
We do not do your work for you.
If you want someone to write your code, you have to pay - I suggest you go to Freelancer.com and ask there.

But be aware: you get what you pay for. Pay peanuts, get monkeys.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900