Bonjour à tous,
Sur un projet je doit insérer google maps, j'ai donc un formulaire qui donne le choix de récupérer les informations (latitude et longitude) selon un corp de métier ou bien selon l'enseigne d'un commerce.
J'ai cette erreur qui apparait :
jquery.js:10099 GET http://localhost/GoogleServices.php
et
No route found for "GET /GoogleServices.php" (from "http://localhost/")
Je vous remercie par avance de toute l'aide que vous m'apporterez !
Pièce jointe 584830
Voici mon code dans mon controller HomeController.php :
Voici le code dans mon service GoogleService.php :Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 /** * @Route("/", name="home") */ public function index(Request $request, CommerceRepository $repositoryCommerce, GoogleServices $googleService): Response { $commerces = $repositoryCommerce->findAll(); $formSearchCommerce = $this->createForm(SearchCommerceType::class); $formSearchCommerce->handleRequest(($request)); if($formSearchCommerce->isSubmitted() && $formSearchCommerce->isValid()) { $corpDeMetier = $formSearchCommerce->get('categories')->getData(); $enseigne = $formSearchCommerce->get('name')->getData(); if($corpDeMetier) { $commerces = $repositoryCommerce->findCommerceByCategories($corpDeMetier); $googleService->getGoogleMapsClient($commerces); } elseif($enseigne) { $commerces = $repositoryCommerce->findBy(['name' => $enseigne]); $googleService->getGoogleMapsClient($commerces); } else { $googleService->getGoogleMapsClient($commerces); $this->addFlash('notice_commerce', 'Veuillez renseigner au moin un champs de recherche.'); } } return $this->render('home/home.html.twig', [ 'formSearchCommerce' => $formSearchCommerce->createView(), ]); }
J'ai ensuite dans mon fichier app.js :Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 /** * fct get profils user bussness */ public function getGooglePlaceClient($placeId) { $url = "https://maps.googleapis.com/maps/api/place/details/json?place_id={$placeId}&lang*uage=fr&fields=business_status,formatted_address,geometry,icon,name,photo,type,url,utc_offset,vicinity,formatted_phone_number,international_phone_number,opening_hours,website,price_level,rating,review,user_ratings_total&key={$this->apiKey}"; $response = $this->clientHttp->request( 'GET', $url, [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'fr-FR', 'Content-Language' => 'fr-FR' ], ] ); if (200 === $response->getStatusCode()) { $content = $response->getContent(); $data = $response->toArray(); return $data['result']; } } /** * fct get maps user latitude et longitude */ public function getGoogleMapsClient($commerces) { if (is_array($commerces) || is_object($commerces)) { foreach($commerces as $data) { if($data->getPlaceId()) { $placeId = $this->getGooglePlaceClient($data->getPlaceId()); $geometry[] = $placeId['geometry']['location']; } } return new JsonResponse(array( 'status' => 'OK', 'data' => $geometry), 200); } }
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 // Attach your callback function to the `window` object window.initMap = function() { // JS API is loaded and available var map = null; var lat = 48.852969; var lon = 2.349903; map = new google.maps.Map(document.getElementById("map"), { center: new google.maps.LatLng(lat, lon), zoom: 11, mapTypeId: google.maps.MapTypeId.ROADMAP, mapTypeControl: true, scrollwheel: false, mapTypeControlOptions: { style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR }, navigationControl: true, navigationControlOptions: { style: google.maps.NavigationControlStyle.ZOOM_PAN } }); // Nous appelons la fonction ajax de jQuery $.ajax({ url : "/GoogleServices", }).done(function(json){ console.log(json); }); };