Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Smarty foreach / Google Mapps DistanceMatrix API

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German
View previous topic :: View next topic  
Author Message
demo1987
Smarty Rookie


Joined: 16 Apr 2014
Posts: 9

PostPosted: Fri Apr 18, 2014 7:04 am    Post subject: Smarty foreach / Google Mapps DistanceMatrix API Reply with quote

Hallo,

ich habe eine kleine Seite mit Smarty (version 3) als templatesystem.

In einer tpl hole ich mir per foreach die einträge aus einer sql tabele und lege für jede eine neue tabellen-zeile an:
Code:
<tbody>
                            {foreach $dispatches as $dispatch}
                               <tr>
                                    <td class="text-center"><input type="checkbox" id="checkbox1-1" name="checkbox1-1"></td>
                                    <td class="text-center">{$dispatch.id}</td>
                                    <td>{$dispatch.dispatch_time|date_format:"%d.%m.%Y, %H:%M:%S"}</td>
                                    <td><a rel="nofollow" href="../admin/mission.php?id={$missions_eintrag.id}">{$dispatch.device_id}</a></td>
                                    <td>{$dispatch.lat} / {$dispatch.long}</td>
                                    <td><div id="outputDiv" ></div></td>
                                    <td class="text-center">
                                        <div class="btn-group btn-group-xs">
                                            <a rel="nofollow" href="../admin/editmission.php?do=edit&id={$missions_eintrag.id}" data-toggle="tooltip" title="" class="btn btn-default" data-original-title="Bearbeiten"><i class="fa fa-pencil"></i></a>
                                            <a rel="nofollow" href="../admin/editmission.php?do=delete&id={$missions_eintrag.id}" data-toggle="tooltip" title="" class="btn btn-default" data-original-title="Löschen"><i class="fa fa-times"></i></a>
                                            <a rel="nofollow" href="../admin/editmission.php?do=archive&id={$missions_eintrag.id}" data-toggle="tooltip" title="" class="btn btn-default" data-original-title="Abschließen"><i class="fa fa-check-circle"></i></a>
                                        </div>
                                    </td>
                                </tr>{/foreach}
                            </tbody>


In einer anderen tpl (der header tpl) will ich per javascript die duration time zwischen zwei koordinaten errechnen und dann in der schleife wieder ausgeben. Genau genommen möchte ich die start-koordinaten (in lat und long - hier fest geschrieben) auch per smarty.variable holen und die jeweilige duration time dann wieder ausgeben:

Code:
<script type="text/javascript">
   
      var origin1 = new google.maps.LatLng(52.898132, 8.433664);
      var destinationA = 'Bremen';
      
      function calculateDistances() {
        var service = new google.maps.DistanceMatrixService();
        service.getDistanceMatrix(
         {
           origins: [origin1],
           destinations: [destinationA],
           travelMode: google.maps.TravelMode.DRIVING,
           unitSystem: google.maps.UnitSystem.METRIC,
           avoidHighways: false,
           avoidTolls: false
         }, callback);
      }

      
      function callback(response, status) {
        if (status != google.maps.DistanceMatrixStatus.OK) {
         alert('Error was: ' + status);
        } else {
         var origins = response.originAddresses;
         var destinations = response.destinationAddresses;
         var outputDiv = document.getElementById('outputDiv');
         outputDiv.innerHTML = '';
      
         for (var i = 0; i < origins.length; i++) {
           var results = response.rows[i].elements;
           for (var j = 0; j < results.length; j++) {
            outputDiv.innerHTML += results[j].duration.text + '<br>';
           }
         }
        }
      }
      
      google.maps.event.addDomListener(window, 'load', initialize);
   
    </script>


Der errechnet mir auch die Zeit - nur weiß ich nicht wie ich das hin und her jetzt in die schleife einbaue.

Ich hoffe jemand hat ne Idee. Meine smarty und javascript kentnisse sind für diese herausforderung leider noch nicht gut genug.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP