Current Lat/Lng output in map

Topics regarding installation and setting up the Btraced on the iPhone

Current Lat/Lng output in map

Postby oddworld » Wed Sep 05, 2012 10:51 am

Hi!

I wonder if someone knows how to show the current position of a map by reading the lat / lng values from mysql.

the current code is now:

function load() {
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(47.6145, -122.3418),
zoom: 13,
mapTypeId: 'roadmap'
});
var infoWindow = new google.maps.InfoWindow;

This code above gives a static lat/lng, so I will need to scroll myself around to search for the pointers that I get. I wonder if its possible that it takes last lat / lng from mysql instead?

Would be very happy if someone knows how to do this.

Best regards.
oddworld
 
Posts: 1
Joined: Wed Sep 05, 2012 10:34 am

Re: Current Lat/Lng output in map

Postby Btraced » Fri Nov 16, 2012 12:32 pm

something like this, but check google olso on this

Code: Select all
  //Read the data from dbase service url
   downloadUrl("find.asp?tripsel="+SelectId+"&IphoneId="+IphoneIdent, function(doc) {
        var xmlDoc = xmlParse(doc);
        var markers = xmlDoc.documentElement.getElementsByTagName("marker");
   map = new google.maps.Map(document.getElementById("div_map"), myOptions);



Find.asp
Code: Select all
<%
dim axml, strsql, alt
Set my_conn = createobject("ADODB.Connection")
my_conn.open = "DRIVER={MySQL ODBC 5.1 Driver};SERVER=localhost;DATABASE=dbasename;UID=Admxxx;PWD=testxxx;OPTION=35;"
strsql = "SELECT *, DATE_FORMAT(datum,'%d-%m-%Y %T') as xdatum FROM gpsdata WHERE travelname = '" & Request.QueryString("tripsel") & "' and iphoneid = '" & Request.QueryString("IphoneId") & "' limit 800"
Set rsa = CreateObject("ADODB.Recordset")
   
rsa.Open strsql, my_conn, 1, 3
if rsa.eof then
   rsa.close
   my_conn.close
   response.redirect "trips.asp"
End if

axml = "<?xml version='1.0' encoding='utf-8'?>" & vbCr & vbLf
axml = axml + "<markers>" & vbCr & vbLf
do while not rsa.eof
   If InStr(rsa("altitude"), "-") > 0 then
      alt = formatnumber(rsa("altitude"),2) & " M under Sealevel"
   Else
      alt = formatnumber(rsa("altitude"),2) & " M Above Sealevel"
   End if
   axml = axml + "<marker lng=" & Chr(34) & rsa("lat") & Chr(34) & " lat=" & Chr(34) & rsa("slong") & Chr(34) & " slbox=" & Chr(34) & dayset(rsa("xdatum")) & Chr(34) & " angle=" & Chr(34) & (rsa("angle")) & Chr(34) & " html=" & chr(34) & dayset(rsa("xdatum")) & "&lt;br/&gt; Speed: " & formatnumber(rsa("Speed"),1) & " km/h" & " " & "&lt;br/&gt; Travel distance: " & formatnumber(rsa("pointdistancetotal"),0) & " mtr" & " "& "&lt;br/&gt; Travel time: " & rsa("traveltimepoint") & " minutes" & " " & "&lt;br/&gt; Altitude: " & alt & " " & "&lt;br/&gt; Battery Status iPhone: " & rsa("phone_battstat") & "%" & chr(34) & " label=" & chr(34) & "Marker one" & chr(34) & "/>" & vbCr & vbLf
   rsa.movenext
loop
axml = axml + "</markers>"
rsa.close
set rsa = nothing
my_conn.close
set my_conn = nothing

Response.write axml
User avatar
Btraced
Site Admin
 
Posts: 60
Joined: Sat Dec 10, 2011 3:03 pm

Re: Current Lat/Lng output in map

Postby Rawin » Tue Sep 03, 2013 11:56 pm

The following I use on my server to display the last added point. It is HTML and PHP combined. Please fill in the appropiate fields for the database and store under "location.php" for instance.

Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en" xml:lang="en">
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   <title>Where is Rawin last seen?</title>
<?php
           $server     = 'localhost';
           $username   = 'user';
           $password   = 'passw';
           $database   = 'btraced';
           $dsn        = "mysql:host=$server;dbname=$database";

  try {
    $db = new PDO($dsn, $username, $password);
    $db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
    // $sth = $db->query("SELECT PointLat, PointLon FROM tblBtracedTripsData ORDER BY id DESC LIMIT 1");

    //$youapp = $sth->fetchAll();
    //echo json_encode( $youapp );
  } catch (Exception $e) {
    echo $e->getMessage();
  }
  // test aera
  $sql = "SELECT PointLat, PointLon FROM tblBtracedTripsData ORDER BY id DESC LIMIT 1;";
   
  $dbRS = $db->query($sql);
  $row = empty($dbRS) ? false : $dbRS->fetch(PDO::FETCH_ASSOC);
  if (!empty($dbRS)) $dbRS->closeCursor();
  // echo $row;
  // var_dump($row);
 
   // var_dump($row["PointLat"]);
   $PointLat = $row["PointLat"];
   $PointLong = $row["PointLon"];
//echo "Lat ->";   
   //echo $PointLat;
   //echo "Long ->";
   //echo $PointLong;
?>


   <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>
   <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>   
   <script type="text/javascript">
      $(document).ready(function () {
         // Define the latitude and longitude positions
         
        var longitudes = <?php echo(json_encode($PointLong)); ?>;
        var latitudes = <?php echo(json_encode($PointLat)); ?>;

         
         var latitude = parseFloat(latitudes);
         var longitude = parseFloat(longitudes);
         var latlngPos = new google.maps.LatLng(latitude, longitude);
         // Set up options for the Google map
         var myOptions = {
            zoom: 10,
            center: latlngPos,
            mapTypeId: google.maps.MapTypeId.ROADMAP
         };
         // Define the map
         map = new google.maps.Map(document.getElementById("map"), myOptions);
         // Add the marker
         var marker = new google.maps.Marker({
            position: latlngPos,
            map: map,
            title: "Where is Rawin?"
         });
      });
   </script>
</head>
<body>
   <div id="map" style="width:462px;height:300px;margin-top:10px;"></div>
</body>
</html>
Rawin
 
Posts: 1
Joined: Tue Aug 20, 2013 8:46 pm


Return to Installation and Configuration

Who is online

Users browsing this forum: No registered users and 1 guest

cron