JavaScript Openlayers - Getting Incorrect LonLat while transform?

I have trying to get Latitude and Longitude of a Point. But While transforming it's not returning the correct LonLat. It's big number that is not a lonlat point for sure.

I have tried for some solutions but didn't get result. What else could be failing?

JS Code I have Tried

map = createMap("deviceMap");
var fromProjection = new OpenLayers.Projection("EPSG:4326"); 
var toProjection = new OpenLayers.Projection("EPSG:900913"); 

map.events.register('click', map, function handleMapClick(e) {
          lonLat = self.map.getLonLatFromViewPortPx(e.xy).
          transform(map.getProjectionObject(), toProjection);
          prompt("",lonLat);
});
Answer:1
  • EPSG:4326
    • should refer to WGS 84,
    • has decimal degree values
  • EPSG:900913
    • refers to WGS84 Web Mercator
    • has metric values, it is x/y axis coordinate system, so "high numbers" are expected

If I understand you right, you should have in variable lonLat a high number.

"LonLat" in OpenLayers does not mean, it will be only longitude/latitude, see documentation here:

  • lon {Number} The x-axis coordinate in map units. If your map is in a geographic projection, this will be the Longitude. Otherwise, it will be the x coordinate of the map location in your map units.

  • lat {Number} The y-axis coordinate in map units. If your map is in a geographic projection, this will be the Latitude. Otherwise, it will be the y coordinate of the map location in your map units.

So if you want to get a real LonLat coordinates, you should not convert it (and use EPSG:4326) or convert it to the other coordinate system, not EPSG:900913.

By the way, OpenLayers started to use 900918 (numeric equivalent to GOOGlE), It was define by Mr. Christopher Schmidt, firstly it was not accepted by European Petroleum Survey Group (EPSG). Then EPSG changed their mind and gave them number: 3857 - WGS84 Pseudo-Mercator.

Answer:2

Here is my problem. After hitting the increment button, y is equal to 7, but z stays equal to 7 instead of changing to 8. Why don't javascript variables update within other variables? Is there a ...

Here is my problem. After hitting the increment button, y is equal to 7, but z stays equal to 7 instead of changing to 8. Why don't javascript variables update within other variables? Is there a ...

  1. change javascript variable to php
  2. change javascript variable in browser
  3. change javascript variable in html
  4. change javascript variable value chrome
  5. change javascript variable in chrome
  6. change javascript variable value
  7. change javascript variable value firefox
  8. change javascript variable from c#
  9. change javascript variable in ajax
  10. javascript change variable
  11. javascript change variable type
  12. javascript change variable in function
  13. javascript change variable name
  14. javascript change variable value in function
  15. javascript change variable value onclick
  16. javascript change variable outside function
  17. javascript change variable inside function
  18. javascript change variable to string
  19. javascript change variable in another file
  20. javascript change variable name in loop

I have created a listview in jquery with a listdivider with a filter. The filter works as expected but as soon as you collapse either of the list dividers, the search subsequently does not work at all,...

I have created a listview in jquery with a listdivider with a filter. The filter works as expected but as soon as you collapse either of the list dividers, the search subsequently does not work at all,...

  1. jquery mobile collapse
  2. jquery mobile collapse dynamically
  3. jquery mobile collapse div
  4. jquery mobile collapse navbar
  5. jquery mobile expand collapse
  6. jquery mobile expand collapse programmatically
  7. menu collapse jquery mobile
  8. jquery mobile collapsible set collapse all
  9. jquery mobile expand collapse div

I have a PHP Function that I would like to integrate into my (existing) web page. Further, I would like it to execute when the user clicks a link on the page. The function needs to accept the text ...

I have a PHP Function that I would like to integrate into my (existing) web page. Further, I would like it to execute when the user clicks a link on the page. The function needs to accept the text ...

  1. calling function through pointer

I have a form in Angular setup like the following. Users can make changes and submit one at a time and it works as expected but I'd like to add a "Submit All" that would submit each item one at a ...

I have a form in Angular setup like the following. Users can make changes and submit one at a time and it works as expected but I'd like to add a "Submit All" that would submit each item one at a ...

  1. submit multiple forms with one button
  2. submit multiple forms with one button powerapps
  3. submit multiple forms with one button jquery
  4. submit multiple forms with one button angular
  5. submit multiple forms powerapps
  6. submit multiple forms with one button ajax
  7. submit multiple forms with one button django
  8. submit multiple forms with one button php
  9. submit multiple forms with ajax
  10. submit multiple forms with one button angular 2
  11. submit multiple forms with one button asp.net mvc
  12. submit multiple forms
  13. submit multiple forms with one button html
  14. submit multiple forms with one button jquery ajax
  15. submit multiple forms at once
  16. submit multiple forms with one button rails
  17. submit multiple forms php
  18. submit multiple forms jquery
  19. submit multiple forms django
  20. submit multiple forms using ajax