Jump to content

google map date format


fgtsai0418

Recommended Posts

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.

Link to comment
Share on other sites

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

my mysql have two different column lat, lng

 

================================================<!DOCTYPE html ><head><meta name="viewport" content="initial-scale=1.0, user-scalable=no" /><meta http-equiv="content-type" content="text/html; charset=UTF-8"/><title>PHP/MySQL & Google Maps Example</title><script type="text/javascript" src="http://maps.googleapis.com/maps/api/j ... "></script><script type="text/javascript">//<![CDATA[var customIcons = {school: {icon: 'http://labs.google.com/ridefinder/images/mm_20_blue.png',shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'},mrt: {icon: 'http://labs.google.com/ridefinder/images/mm_20_red.png',shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'}};function load() {var map = new google.maps.Map(document.getElementById("map"), {center: new google.maps.LatLng(22.621177,120.298311),zoom: 13,mapTypeId: 'roadmap'});var infoWindow = new google.maps.InfoWindow;// Change this depending on the name of your PHP filedownloadUrl("phpsqlajax_genxml.php", function(data) {var xml = data.responseXML;var markers = xml.documentElement.getElementsByTagName("marker");for (var i = 0; i < markers.length; i++) {var name = markers.getAttribute("name");var pointss = new google.maps.LatLng(parseFloat(markers.getAttribute("lat")),parseFloat(markers.getAttribute("lng")));var icon = customIcons[type] || {};var marker = new google.maps.Marker({map: map,position: pointss,icon: icon.icon,shadow: icon.shadow});bindInfoWindow(marker, map, infoWindow, html);}});// Change this depending on the name of your PHP file // Draw a polyline downloadUrl("phpsqlajax_genxml.php", function(data) {var xml = data.responseXML;var markers = xml.documentElement.getElementsByTagName("marker");var path = [];for (var i = 0; i < markers.length; i++) {var lat = parseFloat(markers.getAttribute("lat"));var lng = parseFloat(markers.getAttribute("lng"));var point = new google.maps.LatLng(lat,lng);path.push(point);}//finish loopvar polyline = new google.maps.Polyline({path: path,strokeColor: "#FF0000",strokeOpacity: 1.0,strokeWeight: 2});polyline.setMap(map);}); //end download url}function bindInfoWindow(marker, map, infoWindow, html) {google.maps.event.addListener(marker, 'click', function() {infoWindow.setContent(html);infoWindow.open(map, marker);});}function downloadUrl(url, callback) {var request = window.ActiveXObject ?new ActiveXObject('Microsoft.XMLHTTP') :new XMLHttpRequest;request.onreadystatechange = function() {if (request.readyState == 4) {request.onreadystatechange = doNothing;callback(request, request.status);}};request.open('GET', url, true);request.send(null);}function doNothing() {}//]]></script></head><body onload="load()"><div id="map" style="width: 1000px; height: 500px"></div><p><?$link=mysqli_connect("localhost","name","pass") or die ("無法開啟Mysql資料庫連結"); //建立mysql資料庫連結mysqli_query($link, 'SET NAMES utf8'); mysqli_select_db($link, "markers"); //選擇資料庫markers$sql = "SELECT * FROM markers"; //在markers資料表中選擇所有欄位mysqli_query($link, "SET collation_connection = 'utf8_general_ci'");$result = mysqli_query($link,$sql); // 執行SQL查詢//$row = mysqli_fetch_assoc($result); //將陣列以欄位名索引//$row = mysqli_fetch_row($result); //將陣列以數字排列索引$total_fields=mysqli_num_fields($result); // 取得欄位數$total_records=mysqli_num_rows($result); // 取得記錄數?></p><table border='1'><tr><td>id</td></tr><? for ($i=0;$i<$total_records;$i++) {$row = mysqli_fetch_assoc($result); //將陣列以欄位名索引 ?><tr><td><? echo $row['id']; ?></td></tr><? } ?></table></body></html>

Link to comment
Share on other sites

At this code...

center: new google.maps.LatLng(22.621177,120.298311),

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?

Link to comment
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.

Link to comment
Share on other sites

Can you help me check, why still not working....
function load(User_Id) {
var map = new google.maps.Map(document.getElementById("map_canvas"), {
center: new google.maps.LatLng(22.601914,120.283186),
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infoWindow = new google.maps.InfoWindow;
var geocoder = new google.maps.Geocoder();
// Change this depending on the name of your PHP file
downloadUrl("db_2_xml.php?id="+User_Id, function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("markers");
for (var i = 0; i < markers.length; i++) {
var vessel = markers.getAttribute("vessel");
var geocoder = new google.maps.Geocoder(
geocoder.geocode(markers.getAttribute("GPS")));
/*
var pointss = new google.maps.LatLng(
parseFloat(markers.getAttribute("lat")),
parseFloat(markers.getAttribute("lng")));
*/
var speed = markers.getAttribute("speed");
var icon = customIcons[type] || {};
var marker = new google.maps.Marker({
map: map,
position: geocoder,
icon: icon.icon,
shadow: icon.shadow
});
bindInfoWindow(marker, map, infoWindow, html);
}
});
Edited by fgtsai0418
Link to comment
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.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...