fgtsai0418 Posted June 28, 2013 Share Posted June 28, 2013 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? Link to comment Share on other sites More sharing options...
Ingolme Posted June 28, 2013 Share Posted June 28, 2013 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 More sharing options...
fgtsai0418 Posted June 30, 2013 Author Share Posted June 30, 2013 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 More sharing options...
Ingolme Posted June 30, 2013 Share Posted June 30, 2013 I don't know what you're asking for, can you point out something specific you need help with? Link to comment Share on other sites More sharing options...
fgtsai0418 Posted June 30, 2013 Author Share Posted June 30, 2013 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 More sharing options...
Ingolme Posted June 30, 2013 Share Posted June 30, 2013 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(). Link to comment Share on other sites More sharing options...
fgtsai0418 Posted July 1, 2013 Author Share Posted July 1, 2013 Hi 1. I don't have split() function.. 2. I have change parsefloat and it still not working. Link to comment Share on other sites More sharing options...
Ingolme Posted July 1, 2013 Share Posted July 1, 2013 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 More sharing options...
fgtsai0418 Posted July 2, 2013 Author Share Posted July 2, 2013 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. Link to comment Share on other sites More sharing options...
Ingolme Posted July 3, 2013 Share Posted July 3, 2013 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: split(): http://www.w3schools.com/jsref/jsref_split.asp explode(): http://php.net/explode Link to comment Share on other sites More sharing options...
fgtsai0418 Posted July 5, 2013 Author Share Posted July 5, 2013 I was really too new to understand it Link to comment Share on other sites More sharing options...
fgtsai0418 Posted July 12, 2013 Author Share Posted July 12, 2013 (edited) 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 July 13, 2013 by fgtsai0418 Link to comment Share on other sites More sharing options...
Ingolme Posted July 12, 2013 Share Posted July 12, 2013 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 More sharing options...
fgtsai0418 Posted July 13, 2013 Author Share Posted July 13, 2013 case close Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now