## Recommended Posts

Hello,

When I use "center: new google.maps.LatLng" this command, normally we use (22.621177,120.298311) this format.

But my source is "7 05.16' N, 171 21.88' E"

Did somebody know what to do next?

##### Share on other sites

I assume 05.16 and 21.88 represent minutes. Each minute is 1/60th of a degree. I'll put this in steps to make it easier to understand.

1. First you need to separate the string into three pieces. Javascript's split() function will do that. Your data is now an array, so treat it like one, each piece will have an identifier [0], [1] or [2]

2. Use parseFloat() to turn the first two pieces into numbers.

3. Since each minute is 1/60th of a degree, we multiply it by 1/60th, or what's the same: divide by 60.

4. Now we can add the result to the degrees, which was the first part of the string.

5. Finally, we just need a few if() statements to check whether the value should be positive ("N" or "E") or negative ("S" or "W"). Just multiply the result by -1 if the third part of the string is "S" or "W"

I hope you're able to turn this into code.

##### Share on other sites

This is my code, can you tell me more about geocode function

my mysql have two different column lat, lng

##### Share on other sites

I don't know what you're asking for, can you point out something specific you need help with?

##### Share on other sites

At this code...

google map needs "22.621177,120.298311" this format, but my system provide "22 37.271' N, 120 17.899' E" this format.

And I put all those data in mysql.

How can I made this data transform automatically?

##### Share on other sites

I already pointed out an algorithm that could convert the coordinates for you. All you need to do is wrap it in a function.

It can be done in PHP as well, just change split() for explode() and parseFloat() with floatval().

##### Share on other sites

Hi

1. I don't have split() function..

2. I have change parsefloat and it still not working.

##### Share on other sites

What language are you using to make this? PHP or Javascript?

Javascript has split(), PHP has explode().

Simply using parseFloat() won't solve the problem, you need to do each and every one of the steps I told you.

##### Share on other sites

I am using PHP....

and you mean "It can be done in PHP as well, just change split() for explode()"

But I cannot find out split or explode code in here.

##### Share on other sites

You won't find split() or explode() in your document because you haven't put it there yet. As for finding it in the language reference, I already linked you to it earlier:

explode(): http://php.net/explode

##### Share on other sites

I was really too new to understand it

##### Share on other sites

Can you help me check, why still not working....
var map = new google.maps.Map(document.getElementById("map_canvas"), {
zoom: 13,
});
// Change this depending on the name of your PHP file
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("markers");
for (var i = 0; i < markers.length; i++) {
var vessel = markers.getAttribute("vessel");
geocoder.geocode(markers.getAttribute("GPS")));
/*
parseFloat(markers.getAttribute("lat")),
parseFloat(markers.getAttribute("lng")));
*/
var speed = markers.getAttribute("speed");
var icon = customIcons[type] || {};
map: map,
position: geocoder,
icon: icon.icon,
});
bindInfoWindow(marker, map, infoWindow, html);
}
});
Edited by fgtsai0418
##### Share on other sites

I can't see which part of the code has the data you want to convert, and I don't see the algorithm I gave you implemented in your code.

case close