0

I am passing Latitude and Longitude by link to direction.html file

.../direction.html?latlng=53.456269068499545,-6.220780313014984

how can I get this values to get lat and lng separately

semirturgay
  • 4,151
  • 3
  • 30
  • 50

4 Answers4

3

You can use hashtag, that is passing the value latitude and longitude like this ursite/path#53.456269068499545,-6.220780313014984

var tag = window.location.hash;
tag = tag.substring(1,tag.length);
var co_ordinate = tag.split(",")
var latlng = co_ordinate[0]
var logitude = co_ordinate[1];
Belvi Nosakhare
  • 3,107
  • 5
  • 32
  • 65
0

Because you're passing a single variable, you could just split the data using the comma. The result would be an array.

latlng=53.456269068499545,-6.220780313014984
var res = latlng.split(",");

http://www.w3schools.com/jsref/jsref_split.asp

0

Well Im not sure what language you are using to script the page. I have ideas for PHP.

//you get the variable being passed
if (isset ($_Get['longlat'];) {

$longlat = $_GET['longlat'];

//then you split them with explode
$longlat = explode(',', $longlat); 

$long = $longlat[0];
$lat = $longlat[1];

thats about it. read the manual on explode to get the correct syntax, but this is the gist of what you want i believe

Norman Bird
  • 642
  • 3
  • 10
  • 29
0

You can use split to pull the string into an array, splitting it by the comma, then just assign each of the array's values to a new variable for lat and lng.

I would also parse the data into floats if you are using it as actual coordinate data later on, rather than just printing it.

For:

String latlng=53.456269068499545,-6.220780313014984;

Use:

var coords = latlng.split(",");
float lat = parseFloat(coords[0]);
float lng = parseFloat(coords[1]);
AnthonyMDev
  • 1,496
  • 1
  • 13
  • 27
  • 1
    thanks I already did it : var latlngStr = latlng.split(","); destinationLatitude = parseFloat(latlngStr[0]); destinationLatitude = parseFloat(latlngStr[1]); alert(destinationLatitude); – user3158798 Jan 03 '14 at 22:19
  • 1
    destinationLatitude and other are global variables so I didn't use var – user3158798 Jan 03 '14 at 22:20
  • Great, glad you figured it out. Please remember to mark this question as answered so people stop replying haha! – AnthonyMDev Jan 03 '14 at 22:31