Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP] Naprawa skryptu pobieranie danych z google maps
Jump0ncash
post 24.01.2019, 15:34:30
Post #1





Grupa: Zarejestrowani
Postów: 23
Pomógł: 0
Dołączył: 10.09.2006

Ostrzeżenie: (40%)
XX---


Witajcie mam problem, osoba która mi robiła strona nie odzywa się a zaszły jak wiecie zmiany w api i coś nie działa skrypt poprawnie.

Mianowicie skrypt wyglądał następująco:

  1. <?php
  2. $cities = '';
  3. $result = eco_db_query("SELECT * FROM `-data-cities-province-poland` WHERE province = '" . eco_db_str($_GET['woj']) . "' ORDER BY city ASC");
  4. while($row = eco_db_fetch_array($result)) :
  5. if ($row['city'] != $miasto):
  6. $cities .= '<a href="/kategoria/' . eco_db_str($_GET['woj']) . '/' . eco_alias($row['city']) . '">' . $row['city'] . '</a>, ';
  7. endif;
  8. endwhile;
  9. $cities = trim($cities,", ");
  10.  
  11.  
  12. $details = "http://maps.googleapis.com/maps/api/distancematrix/json?origins=53.470937,21.121377&destinations=" . str_replace(" ","-",$miasto) . "," . $_GET['woj'] . "&mode=driving&sensor=false";
  13. $json = file_get_contents($details);
  14. $details = json_decode($json, TRUE);
  15. $distance = $details['rows'][0]['elements'][0]['distance']['text'];
  16. $distance_raw = trim($distance," km");
  17. $distance_raw = str_replace(",","",$distance_raw);
  18. $transport_price = ($distance_raw * 6) / 3;
  19. if ($distance_raw < 100) { $transport_price = $transport_price + 150;}
  20. $transport_price = eco_money(floor($transport_price)) . 'PLN';
  21.  
  22.  
  23. $output = content(43, 78);
  24. $output = str_replace("{TRANSPORT:DYSTANS}",$distance,$output);
  25. $output = str_replace("{TRANSPORT:KOSZT}",$transport_price,$output);
  26. $output = str_replace("{WOJEWODZTWO}",ucfirst($_GET['woj']),$output);
  27. $output = str_replace("{MIASTA}",ucfirst($cities),$output);
  28. $output = str_replace("{MIASTO}",$miasto,$output);
  29.  
  30. echo $output;
  31.  
  32. ?>


Myślałem że chodzi o dołożenie klucza do adresu googlemaps i zrobiłem coś takiego:
  1. <?php
  2. $cities = '';
  3. $result = eco_db_query("SELECT * FROM `-data-cities-province-poland` WHERE province = '" . eco_db_str($_GET['woj']) . "' ORDER BY city ASC");
  4. while($row = eco_db_fetch_array($result)) :
  5. if ($row['city'] != $miasto):
  6. $cities .= '<a href="/kategoria/' . eco_db_str($_GET['woj']) . '/' . eco_alias($row['city']) . '">' . $row['city'] . '</a>, ';
  7. endif;
  8. endwhile;
  9. $cities = trim($cities,", ");
  10.  
  11.  
  12. $details = "http://maps.googleapis.com/maps/api/distancematrix/json?origins=53.470937,21.121377&destinations=" . str_replace(" ","-",$miasto) . "," . $_GET['woj'] . "&mode=driving&sensor=false&key=MÓJKLUCZ";
  13. $json = file_get_contents($details);
  14. $details = json_decode($json, TRUE);
  15. $distance = $details['rows'][0]['elements'][0]['distance']['text'];
  16. $distance_raw = trim($distance," km");
  17. $distance_raw = str_replace(",","",$distance_raw);
  18. $transport_price = ($distance_raw * 6) / 3;
  19. if ($distance_raw < 100) { $transport_price = $transport_price + 150;}
  20. $transport_price = eco_money(floor($transport_price)) . 'PLN';
  21.  
  22.  
  23. $output = content(43, 78);
  24. $output = str_replace("{TRANSPORT:DYSTANS}",$distance,$output);
  25. $output = str_replace("{TRANSPORT:KOSZT}",$transport_price,$output);
  26. $output = str_replace("{WOJEWODZTWO}",ucfirst($_GET['woj']),$output);
  27. $output = str_replace("{MIASTA}",ucfirst($cities),$output);
  28. $output = str_replace("{MIASTO}",$miasto,$output);
  29.  
  30. echo $output;
  31.  
  32. ?>


Niestety nic to nie pomogło wyświetla się error: Notice: Undefined offset: 0 in /home...... in line 65

Linia 65 to akurat
$distance = $details['rows'][0]['elements'][0]['distance']['text'];


TEMAT Do zamknięcia - patrzyłem się na to i nie zauważyłem że trzeba było dopisać literkę "s" na http adresu googla

Ten post edytował Jump0ncash 24.01.2019, 15:39:13
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 29.03.2024 - 11:39