Help with google maps api

1

I'm a beginner in HTML and PHP, I would like to know how I can via google maps API make a site-like routine on my site mapeia.com , where I receive the mileage and time information of a route informed by the user.

    
asked by anonymous 23.05.2017 / 21:00

1 answer

0

Simple answer: A lot of PHP (or the server language of your choice), a lot of javascript, a lot of documentation reading and some HTML

Not so simple answer: This will require some of your creativity. The google API gives you support for you to use in your applications, it does not give you the solution ready. I recommend doing several tests of the documentation (study it yourself, as if it were chapter by chapter ), test multiple map templates, make changes. There are the codes. Another way to get inspired is to know what other developers are doing with Google Maps API. In this link has an excellent repository in github with several examples ready for you to test in your search. What you might twist your nose at is that beginners (as you say it is) may not have as much intimacy with the database. If this is the case, I recommend studying JSON's file-read pattern, studying the json_decode function. of PHP, and also study the fwrite file writing function. Later you can do this JSON reading from a database (it is possible). Before you start with the most ingenious part, you can simply pass GET parameters in the url to test a dynamism.

Example of using the json_decode function:

<?php
$arquivo = "teste.json"; // Sempre colocar caminho completo para possível saída HTTP. Configurar token.php para evitar acessos indevidos. 
$info    = file_get_contents($arquivo);
$lendo   = json_decode($info);
foreach ($lendo->dados as $reg) {
                echo "<b>id:</b> " . $reg->id."<br>";
                echo "<br /><b>categoria:</b> " . $reg->Categoria."<br>";
                echo "<br /><b>titulo:</b> " . $reg->titulo ."<br>";
}

?>

Used JSON file

{
    "dados":[ {
        "id": "1", "Categoria": "Blog", "titulo": "Minha postagem"
    }
    ,
    {
        "Id": "0", "Categoria": "00000", "Titulo": "000000"
    }
    ]
}

Example of a map receiving data via PHP URL

<?php
$pegaLatitude = $_GET['lat]';
$pegaLongitude = $_GET['lng]';

?>
    <!DOCTYPE html>
    <html>
      <head>
        <title>Simple Map</title>
        <meta name="viewport" content="initial-scale=1.0">
        <meta charset="utf-8">
        <style>
          /* Always set the map height explicitly to define the size of the div
           * element that contains the map. */
          #map {
            height: 100%;
          }
          /* Optional: Makes the sample page fill the window. */
          html, body {
            height: 100%;
            margin: 0;
            padding: 0;
          }
        </style>
      </head>
      <body>
        <div id="map"></div>
        <script>
          var map;
          function initMap() {
            map = new google.maps.Map(document.getElementById('map'), {
              center: {lat: <?php echo $pegaLatidude; ?>, lng: <?php echo $pegaLongitude; ?>},
              zoom: 8
            });
          }
        </script>
        <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap"asyncdefer></script></body></html>
  

Conclusion:TheMapsAPIonlyprovidesthe  manipulationofmaps.Theroleofthedeveloperistodeliver  Marketplace.Study,butdonotbeawiker,beadeveloper.Create  systems,solutions.Andespecially,trynottoassociate  yourproblemsolvingabilityatonlylimits  ofknowledge.Muchofthedeveloperroutineistouse  knowledgeresourcesofotherdevelopers,usingAPIs,  librariesandframeworks.Sodonotbeafraidto  search/ask/etc.Anddonotforgettogetyourdeveloperkeyforyourmapstowork.Moreexplanationonthis link

    
23.05.2017 / 22:14