Convert LatLng to (x, y) coordinates
I'm working on Google maps which will show multiple vehicles. I've two points(one point which will be the old position and other will be the present position) this positioning system will help write an equation of a line passing through these two points. Which might intersect with other line and inform me about the probability of collision.
But the problem is that I'm fetching the coordinates from the GPS module and it will give the location in Latitude and Longitude format.
I'll need x, y coordinates for this writing the equation of the line passing through them. I've already explored most of the method in different web pages, but the problem is that they will ask for some screen size(or map bounds) which are kind of not compatible with my type of method.
Questions: What is the method to convert Latitude and Longitude to (x, y) coordinates, just like if we see from the space and earth was flat and taking Gulf of Guinea (Lat: 0°, Lon: 0°) as the origin.
google-maps google-maps-api-3 maps latitude-longitude
add a comment |
I'm working on Google maps which will show multiple vehicles. I've two points(one point which will be the old position and other will be the present position) this positioning system will help write an equation of a line passing through these two points. Which might intersect with other line and inform me about the probability of collision.
But the problem is that I'm fetching the coordinates from the GPS module and it will give the location in Latitude and Longitude format.
I'll need x, y coordinates for this writing the equation of the line passing through them. I've already explored most of the method in different web pages, but the problem is that they will ask for some screen size(or map bounds) which are kind of not compatible with my type of method.
Questions: What is the method to convert Latitude and Longitude to (x, y) coordinates, just like if we see from the space and earth was flat and taking Gulf of Guinea (Lat: 0°, Lon: 0°) as the origin.
google-maps google-maps-api-3 maps latitude-longitude
3
developers.google.com/maps/documentation/javascript/reference/…
– MrUpsidown
Nov 21 '18 at 9:44
add a comment |
I'm working on Google maps which will show multiple vehicles. I've two points(one point which will be the old position and other will be the present position) this positioning system will help write an equation of a line passing through these two points. Which might intersect with other line and inform me about the probability of collision.
But the problem is that I'm fetching the coordinates from the GPS module and it will give the location in Latitude and Longitude format.
I'll need x, y coordinates for this writing the equation of the line passing through them. I've already explored most of the method in different web pages, but the problem is that they will ask for some screen size(or map bounds) which are kind of not compatible with my type of method.
Questions: What is the method to convert Latitude and Longitude to (x, y) coordinates, just like if we see from the space and earth was flat and taking Gulf of Guinea (Lat: 0°, Lon: 0°) as the origin.
google-maps google-maps-api-3 maps latitude-longitude
I'm working on Google maps which will show multiple vehicles. I've two points(one point which will be the old position and other will be the present position) this positioning system will help write an equation of a line passing through these two points. Which might intersect with other line and inform me about the probability of collision.
But the problem is that I'm fetching the coordinates from the GPS module and it will give the location in Latitude and Longitude format.
I'll need x, y coordinates for this writing the equation of the line passing through them. I've already explored most of the method in different web pages, but the problem is that they will ask for some screen size(or map bounds) which are kind of not compatible with my type of method.
Questions: What is the method to convert Latitude and Longitude to (x, y) coordinates, just like if we see from the space and earth was flat and taking Gulf of Guinea (Lat: 0°, Lon: 0°) as the origin.
google-maps google-maps-api-3 maps latitude-longitude
google-maps google-maps-api-3 maps latitude-longitude
asked Nov 21 '18 at 9:30
Arshdeep Singh
398
398
3
developers.google.com/maps/documentation/javascript/reference/…
– MrUpsidown
Nov 21 '18 at 9:44
add a comment |
3
developers.google.com/maps/documentation/javascript/reference/…
– MrUpsidown
Nov 21 '18 at 9:44
3
3
developers.google.com/maps/documentation/javascript/reference/…
– MrUpsidown
Nov 21 '18 at 9:44
developers.google.com/maps/documentation/javascript/reference/…
– MrUpsidown
Nov 21 '18 at 9:44
add a comment |
2 Answers
2
active
oldest
votes
If your task requires high accuracy you have to use Latitude/Longitude and to solve Great Circle intersection task. The Earth is not flat.
If you can accept existence of some error in your calculations AND all of your vehicles are located in small limited area (up to 100km, although it depends on error you can accept) you may assume this confined area as flat.
For instance, if one your vehicle is located at N10.0 E10.0, second one is located at N10.1 E10.2, you may choose N10.0 E10.0 as the origin.
As a result, these two vehicles will have the following (X, Y) coords (it assumes that axis X goes along equator):
1) (0.0km 0.0km)
2) (21.86km 11.1km)
X of second vehicle is (40000km / 360 degrees) * cos(10.0) * (10.2 - 10.0) = 21.86km
Y of second vehicle is (40000km / 360 degrees) * (10.1 - 10.0) = 11.1km
If you will try to apply flat line-line intersection for vehicles located in 10 000 km from each other - your calcutions most probably will be incorrect.
He's asking for x,y coordinates for an equation he already has. Not to solve the problem on the sphere. The vehicles are presumebly cars.
– lusitanica
Nov 21 '18 at 11:25
Ok. Author tries to find trajectory intersection actually. If he tries to use trivial line equation like ax + by = c for two distant vehicles the result can be erroneous. However such equation can be used (with some acceptable error) if distance between vehicles is small.
– Alexey Kornev
Nov 21 '18 at 11:36
Yup, if they are about to intercept the distance will be really, really small.
– lusitanica
Nov 21 '18 at 11:40
add a comment |
For small distances Pythagoras’ theorem can be used on an equirectangular projection:
var x = (λ2-λ1) * Math.cos((φ1+φ2)/2);
var y = (φ2-φ1);
Where φ1, λ1= 0 (according to the end of your last paragraph).
Note that you can use x,y as input for your equations, but not to visualize on Google Maps.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53408922%2fconvert-latlng-to-x-y-coordinates%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
If your task requires high accuracy you have to use Latitude/Longitude and to solve Great Circle intersection task. The Earth is not flat.
If you can accept existence of some error in your calculations AND all of your vehicles are located in small limited area (up to 100km, although it depends on error you can accept) you may assume this confined area as flat.
For instance, if one your vehicle is located at N10.0 E10.0, second one is located at N10.1 E10.2, you may choose N10.0 E10.0 as the origin.
As a result, these two vehicles will have the following (X, Y) coords (it assumes that axis X goes along equator):
1) (0.0km 0.0km)
2) (21.86km 11.1km)
X of second vehicle is (40000km / 360 degrees) * cos(10.0) * (10.2 - 10.0) = 21.86km
Y of second vehicle is (40000km / 360 degrees) * (10.1 - 10.0) = 11.1km
If you will try to apply flat line-line intersection for vehicles located in 10 000 km from each other - your calcutions most probably will be incorrect.
He's asking for x,y coordinates for an equation he already has. Not to solve the problem on the sphere. The vehicles are presumebly cars.
– lusitanica
Nov 21 '18 at 11:25
Ok. Author tries to find trajectory intersection actually. If he tries to use trivial line equation like ax + by = c for two distant vehicles the result can be erroneous. However such equation can be used (with some acceptable error) if distance between vehicles is small.
– Alexey Kornev
Nov 21 '18 at 11:36
Yup, if they are about to intercept the distance will be really, really small.
– lusitanica
Nov 21 '18 at 11:40
add a comment |
If your task requires high accuracy you have to use Latitude/Longitude and to solve Great Circle intersection task. The Earth is not flat.
If you can accept existence of some error in your calculations AND all of your vehicles are located in small limited area (up to 100km, although it depends on error you can accept) you may assume this confined area as flat.
For instance, if one your vehicle is located at N10.0 E10.0, second one is located at N10.1 E10.2, you may choose N10.0 E10.0 as the origin.
As a result, these two vehicles will have the following (X, Y) coords (it assumes that axis X goes along equator):
1) (0.0km 0.0km)
2) (21.86km 11.1km)
X of second vehicle is (40000km / 360 degrees) * cos(10.0) * (10.2 - 10.0) = 21.86km
Y of second vehicle is (40000km / 360 degrees) * (10.1 - 10.0) = 11.1km
If you will try to apply flat line-line intersection for vehicles located in 10 000 km from each other - your calcutions most probably will be incorrect.
He's asking for x,y coordinates for an equation he already has. Not to solve the problem on the sphere. The vehicles are presumebly cars.
– lusitanica
Nov 21 '18 at 11:25
Ok. Author tries to find trajectory intersection actually. If he tries to use trivial line equation like ax + by = c for two distant vehicles the result can be erroneous. However such equation can be used (with some acceptable error) if distance between vehicles is small.
– Alexey Kornev
Nov 21 '18 at 11:36
Yup, if they are about to intercept the distance will be really, really small.
– lusitanica
Nov 21 '18 at 11:40
add a comment |
If your task requires high accuracy you have to use Latitude/Longitude and to solve Great Circle intersection task. The Earth is not flat.
If you can accept existence of some error in your calculations AND all of your vehicles are located in small limited area (up to 100km, although it depends on error you can accept) you may assume this confined area as flat.
For instance, if one your vehicle is located at N10.0 E10.0, second one is located at N10.1 E10.2, you may choose N10.0 E10.0 as the origin.
As a result, these two vehicles will have the following (X, Y) coords (it assumes that axis X goes along equator):
1) (0.0km 0.0km)
2) (21.86km 11.1km)
X of second vehicle is (40000km / 360 degrees) * cos(10.0) * (10.2 - 10.0) = 21.86km
Y of second vehicle is (40000km / 360 degrees) * (10.1 - 10.0) = 11.1km
If you will try to apply flat line-line intersection for vehicles located in 10 000 km from each other - your calcutions most probably will be incorrect.
If your task requires high accuracy you have to use Latitude/Longitude and to solve Great Circle intersection task. The Earth is not flat.
If you can accept existence of some error in your calculations AND all of your vehicles are located in small limited area (up to 100km, although it depends on error you can accept) you may assume this confined area as flat.
For instance, if one your vehicle is located at N10.0 E10.0, second one is located at N10.1 E10.2, you may choose N10.0 E10.0 as the origin.
As a result, these two vehicles will have the following (X, Y) coords (it assumes that axis X goes along equator):
1) (0.0km 0.0km)
2) (21.86km 11.1km)
X of second vehicle is (40000km / 360 degrees) * cos(10.0) * (10.2 - 10.0) = 21.86km
Y of second vehicle is (40000km / 360 degrees) * (10.1 - 10.0) = 11.1km
If you will try to apply flat line-line intersection for vehicles located in 10 000 km from each other - your calcutions most probably will be incorrect.
answered Nov 21 '18 at 11:20
Alexey Kornev
262
262
He's asking for x,y coordinates for an equation he already has. Not to solve the problem on the sphere. The vehicles are presumebly cars.
– lusitanica
Nov 21 '18 at 11:25
Ok. Author tries to find trajectory intersection actually. If he tries to use trivial line equation like ax + by = c for two distant vehicles the result can be erroneous. However such equation can be used (with some acceptable error) if distance between vehicles is small.
– Alexey Kornev
Nov 21 '18 at 11:36
Yup, if they are about to intercept the distance will be really, really small.
– lusitanica
Nov 21 '18 at 11:40
add a comment |
He's asking for x,y coordinates for an equation he already has. Not to solve the problem on the sphere. The vehicles are presumebly cars.
– lusitanica
Nov 21 '18 at 11:25
Ok. Author tries to find trajectory intersection actually. If he tries to use trivial line equation like ax + by = c for two distant vehicles the result can be erroneous. However such equation can be used (with some acceptable error) if distance between vehicles is small.
– Alexey Kornev
Nov 21 '18 at 11:36
Yup, if they are about to intercept the distance will be really, really small.
– lusitanica
Nov 21 '18 at 11:40
He's asking for x,y coordinates for an equation he already has. Not to solve the problem on the sphere. The vehicles are presumebly cars.
– lusitanica
Nov 21 '18 at 11:25
He's asking for x,y coordinates for an equation he already has. Not to solve the problem on the sphere. The vehicles are presumebly cars.
– lusitanica
Nov 21 '18 at 11:25
Ok. Author tries to find trajectory intersection actually. If he tries to use trivial line equation like ax + by = c for two distant vehicles the result can be erroneous. However such equation can be used (with some acceptable error) if distance between vehicles is small.
– Alexey Kornev
Nov 21 '18 at 11:36
Ok. Author tries to find trajectory intersection actually. If he tries to use trivial line equation like ax + by = c for two distant vehicles the result can be erroneous. However such equation can be used (with some acceptable error) if distance between vehicles is small.
– Alexey Kornev
Nov 21 '18 at 11:36
Yup, if they are about to intercept the distance will be really, really small.
– lusitanica
Nov 21 '18 at 11:40
Yup, if they are about to intercept the distance will be really, really small.
– lusitanica
Nov 21 '18 at 11:40
add a comment |
For small distances Pythagoras’ theorem can be used on an equirectangular projection:
var x = (λ2-λ1) * Math.cos((φ1+φ2)/2);
var y = (φ2-φ1);
Where φ1, λ1= 0 (according to the end of your last paragraph).
Note that you can use x,y as input for your equations, but not to visualize on Google Maps.
add a comment |
For small distances Pythagoras’ theorem can be used on an equirectangular projection:
var x = (λ2-λ1) * Math.cos((φ1+φ2)/2);
var y = (φ2-φ1);
Where φ1, λ1= 0 (according to the end of your last paragraph).
Note that you can use x,y as input for your equations, but not to visualize on Google Maps.
add a comment |
For small distances Pythagoras’ theorem can be used on an equirectangular projection:
var x = (λ2-λ1) * Math.cos((φ1+φ2)/2);
var y = (φ2-φ1);
Where φ1, λ1= 0 (according to the end of your last paragraph).
Note that you can use x,y as input for your equations, but not to visualize on Google Maps.
For small distances Pythagoras’ theorem can be used on an equirectangular projection:
var x = (λ2-λ1) * Math.cos((φ1+φ2)/2);
var y = (φ2-φ1);
Where φ1, λ1= 0 (according to the end of your last paragraph).
Note that you can use x,y as input for your equations, but not to visualize on Google Maps.
edited Nov 21 '18 at 11:08
answered Nov 21 '18 at 10:38
lusitanica
45829
45829
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53408922%2fconvert-latlng-to-x-y-coordinates%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
developers.google.com/maps/documentation/javascript/reference/…
– MrUpsidown
Nov 21 '18 at 9:44