2016-03-25 23 views
0
üzerinde çalışır

Bu, localhost üzerinde harika çalışır, ancak çevrimiçi çalışmayacaktır. Her yerde bir düzeltme için baktım. Sunucu ve tarayıcı için bir Google anahtarını denedim. Bir tarayıcıda URL koymak Coğrafi kodlamaya çevrimiçi olarak çalışabilir, ancak localhost

, ben lat ve uzun ile doğru yanıt almak. Ancak kodu yüklediğimde, lat ve uzun çekmeyecek. Lat ve uzun süre manuel olarak koyabilirim ve harika çalışıyor. Herhangi bir yardım Muhteşem olacak.

"https://maps.google.com/maps/api/geocode/json?address=458+4th+st,+Atwater,+California,+95301&key=My_key" 


<?php require_once("includes/connection.php"); 
      $id=$_GET['id']; 
      $id=64; 
      $query = "SELECT * FROM events WHERE id = '".$id."'"; 
      $result=mysql_query($query); 
       while($row2 = mysql_fetch_assoc($result)){ 
        $name=$row2['name']; 
        $add = $row2['address']." ".$row2['city']." ".$row2['state']." ".$row2['zip']; 
        } 

     ?> 


      <link media="all" type="text/css" href="http://fonts.googleapis.com/css?family=Open+Sans:400,300,300italic,400italic,600,600italic,700,700italic,800,800italic" rel="stylesheet"> 

      <script type='text/javascript' src='assets/jquery.js'></script> 
      <script type='text/javascript' src='assets/jquery-migrate.js'></script> 

      <?php /* === GOOGLE MAP JAVASCRIPT NEEDED (JQUERY) ==== */ ?> 
      <script src="http://maps.google.com/maps/api/js?sensor=true" type="text/javascript"></script> 
      <script type='text/javascript' src='assets/one_marker_gmaps.js'></script> 


       <body> 
        <div id="container"> 

         <article class="entry"> 


          <div class="entry-content"> 

           <?php 
            // Get lat and long by address   
             $address = $add; // Google HQ 
             $prepAddr = str_replace(' ','+',$address); 
             $geocode=file_get_contents('https://maps.google.com/maps/api/geocode/json?address=458+4th+st,+Atwater,+California,+95301&key=AIzaSyAgo83mZXhQCFzF2Y3pQYJUC1ivAXKwiX4'); 
             $output= json_decode($geocode); 
             $latitude = $output->results[0]->geometry->location->lat; 
             $longitude = $output->results[0]->geometry->location->lng; 

           ?> 

           <?php /* === THIS IS WHERE WE WILL ADD OUR MAP USING JS ==== */ ?> 
            <div class="google-map-wrap" itemscope itemprop="hasMap" itemtype="http://schema.org/Map"> 
             <div id="google-map" class="google-map"> 
             </div><!-- #google-map --> 
            </div> 

           <?php /* === MAP DATA === */ ?> 
           <?php 
            $locations = array(); 

            /* Marker #1 */ 
            $locations[] = array(
             'google_map' => array(
              'lat' => $latitude, 
              'lng' => $longitude, 
             ), 
             'location_address' => 'Puri Anjasmoro B1/22 Semarang', 
             'location_name' => 'Loc A', 
           ); 

           ?> 


           <?php /* === PRINT THE JAVASCRIPT === */ ?> 

           <?php 
            /* Set Default Map Area Using First Location */ 
            $map_area_lat = isset($locations[0]['google_map']['lat']) ? $locations[0]['google_map']['lat'] : ''; 
            $map_area_lng = isset($locations[0]['google_map']['lng']) ? $locations[0]['google_map']['lng'] : ''; 
           ?> 

           <script> 
            jQuery(document).ready(function($) { 

             /* Do not drag on mobile. */ 
             var is_touch_device = 'ontouchstart' in document.documentElement; 

             var map = new GMaps({ 
              el: '#google-map', 
              lat: '<?php echo $map_area_lat; ?>', 
              lng: '<?php echo $map_area_lng; ?>', 
              scrollwheel: true, 
              zoom: 5, 
              draggable: ! is_touch_device 
             }); 

            /* Map Bound */ 
            var bounds = []; 

            <?php /* For Each Location Create a Marker. */ 
             foreach($locations as $location){ 
              $name2 = $location['location_name']; 
              $addr = $location['location_address']; 
              $map_lat = $location['google_map']['lat']; 
              $map_lng = $location['google_map']['lng']; 
              ?> 
              /* Set Bound Marker */ 
              var latlng = new google.maps.LatLng(<?php echo $map_lat; ?>, <?php echo $map_lng; ?>); 
              bounds.push(latlng); 
              /* Add Marker */ 
              map.addMarker({ 
               lat: <?php echo $map_lat; ?>, 
               lng: <?php echo $map_lng; ?>, 
               title: '<?php echo $name; ?>', 
               infoWindow: { 
                content: '<?php echo $name; ?>' 
               } 
              }); 
            <?php } //end foreach locations ?> 

             /* Fit All Marker to map */ 
             map.fitLatLngBounds(bounds); 

             /* Make Map Responsive */ 
             var $window = $(window); 
             function mapWidth() { 
              var size = $('.google-map-wrap').width(); 
              $('.google-map').css({width: size + 'px', height: (size/2) + 'px'}); 
             } 
             mapWidth(); 
             $(window).resize(mapWidth); 

            }); 
           </script> 
+0

onay var_dump (çıkış); Bu API için günlük istek kotanızı aştınız olabilir. Sunucunuz paylaşılan bir sunucuda mı? Başka biri kotayı kullanabilirdi – channasmcs

cevap

0

Bunu test ettiğimde, file_get_contents öğesinin yanlış döndüğü anlaşılıyor. Curl'i denedin mi?

$url = 'https://maps.google.com/maps/api/geocode/json?address=458+4th+st,+Atwater,+California,+95301&key=AIzaSyAgo83mZXhQCFzF2Y3pQYJUC1ivAXKwiX4'; 

$curl = curl_init();curl_setopt($curl, CURLOPT_URL, $url); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($curl, CURLOPT_HEADER, false); 
$data = curl_exec($curl); 
curl_close($curl); 
$output= json_decode($data); 
İlgili konular