Google Map ไม่แสดงค่ะ (phpbb)

สำหรับผู้ที่ เริ่มต้น Programming - PHP มีอะไร แนะนำ หรือข้อสงสัยต้องบอร์ด นี้ คนที่มีความรู้ แบ่งปันคนอื่นบ้างนะ ปัญหาการเขียนโปรแกรม แบบ OOP Session Cookies php network

Moderator: mindphp, ผู้ดูแลกระดาน

ภาพประจำตัวสมาชิก
M030
PHP Super Hero Member
PHP Super Hero Member
โพสต์: 532
ลงทะเบียนเมื่อ: 07/09/2015 10:06 am

Google Map ไม่แสดงค่ะ (phpbb)

โพสต์ที่ยังไม่ได้อ่าน โดย M030 »

google map ไม่แสดงค่ะ มันขึ้นว่า status เราว่าง
status.png
status.png (2.72 KiB) Viewed 1122 times
โค้ด ***.php

โค้ด: เลือกทั้งหมด

  $search_txt = request_var('search_txt', '', true);
  $address = request_var('address', '', true);
  
   $address = $search_txt;
        ///// Google Map ////////
        $address = urlencode($address); //  $address = เสนานิคม เราสามารถ Get หรือ ทำเป็นฟอร์มรับค่ามาก่อนได้
        $url = "http://maps.google.com/maps/api/geocode/json?sensor=false&address={$address}";


        $resp_json = file_get_contents($url);
        print_r($resp_json);
        exit; // เมื่อปริ้นค่าออกมาจะได้ข้อมูล Json เเบบตัวอย่างข้างต้น

        $resp = json_decode($resp_json, true); // เอาออกจาก Json สะ เอามาใช้ต่อ
        if ($resp['status'] == 'OK') {

            // get the important data
            $lati = $resp['results'][0]['geometry']['location']['lat'];
            $longi = $resp['results'][0]['geometry']['location']['lng'];
            $formatted_address = $resp['results'][0]['formatted_address'];
            print_r($lati);
            echo '<hr>'; // 13.8340589
            print_r($longi);
            echo '<hr>'; //100.5723563
            print_r($formatted_address); //ซอยเสนานิคม แขวง ลาดยาว เขต จตุจักร กรุงเทพมหานคร 10900, Thailand
            exit;
        }
โค้ด ***.html

โค้ด: เลือกทั้งหมด

<div id="gmap_canvas">
             <!-- JavaScript to show google map -->
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>    
    <script type="text/javascript">
        function init_map() {
            var myOptions = {
                zoom: 14,
                center: new google.maps.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>),
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            map = new google.maps.Map(document.getElementById("gmap_canvas"), myOptions);
            marker = new google.maps.Marker({
                map: map,
                position: new google.maps.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>)
            });
            infowindow = new google.maps.InfoWindow({
                content: "<?php echo $formatted_address; ?>" 
            });
            google.maps.event.addListener(marker, "click", function () {
                infowindow.open(map, marker);
            });
            infowindow.open(map, marker);
        }
        google.maps.event.addDomListener(window, 'load', init_map);
    </script>
        </div> 
ภาพประจำตัวสมาชิก
M030
PHP Super Hero Member
PHP Super Hero Member
โพสต์: 532
ลงทะเบียนเมื่อ: 07/09/2015 10:06 am

Re: Google Map ไม่แสดงค่ะ (phpbb)

โพสต์ที่ยังไม่ได้อ่าน โดย M030 »

ตอนนี้มันขึ้น error แบบนี้แล้วค่ะ

โค้ด: เลือกทั้งหมด

[phpBB Debug] PHP Warning: in file [ROOT]/ext/mindphp/m_thaipost/controller/m_thaipost.php on line 221: file_get_contents(http://maps.google.com/maps/api/geocode/json?sensor=false&address=%E0%B8%AB%E0%B8%99%E0%B8%AD%E0%B8%87%E0%B8%88%E0%B8%AD%E0%B8%81): failed to open stream: HTTP request failed! 
ภาพประจำตัวสมาชิก
thatsawan
PHP VIP Members
PHP VIP Members
โพสต์: 28508
ลงทะเบียนเมื่อ: 31/03/2014 10:02 am
ติดต่อ:

Re: Google Map ไม่แสดงค่ะ (phpbb)

โพสต์ที่ยังไม่ได้อ่าน โดย thatsawan »

M030 เขียน:$search_txt = request_var('search_txt', '', true);
$address = request_var('address', '', true);

$address = $search_txt;
ต้องการอะไรค่ะ ตรงนี้ ?
รับต่า $address มาจากใหน ? เเล้วถ้าจะให้ = $search_txt จะรับค่า $address ทำไมค่ะ


ลอง echo $address ว่าได้ค่าที่จะเอามาหรือป่าว

โค้ด: เลือกทั้งหมด

        $address = urlencode('หนองจอก') ;
        $url = "http://maps.google.com/maps/api/geocode/json?sensor=false&address=$address";
        $a = file_get_contents($url);
        
        print_r($a); exit; 

โค้ด: เลือกทั้งหมด

{ "results" : [ { "address_components" : [ { "long_name" : "Nong Chok", "short_name" : "Nong Chok", "types" : [ "natural_feature", "establishment" ] }, { "long_name" : "Kui Buri", "short_name" : "Kui Buri", "types" : [ "locality", "political" ] }, { "long_name" : "Kui Buri District", "short_name" : "Kui Buri District", "types" : [ "administrative_area_level_2", "political" ] }, { "long_name" : "Prachuap Khiri Khan", "short_name" : "เธˆ.เธ›เธฃเธฐเธˆเธงเธšเธ„เธตเธฃเธตเธ‚เธฑเธ™เธ˜เนŒ", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "Thailand", "short_name" : "TH", "types" : [ "country", "political" ] }, { "long_name" : "77150", "short_name" : "77150", "types" : [ "postal_code" ] } ], "formatted_address" : "Nong Chok, Kui Buri, Kui Buri District, Prachuap Khiri Khan 77150, Thailand", "geometry" : { "bounds" : { "northeast" : { "lat" : 12.0546981, "lng" : 99.8409453 }, "southwest" : { "lat" : 12.0522011, "lng" : 99.83263769999999 } }, "location" : { "lat" : 12.0533801, "lng" : 99.84004700000001 }, "location_type" : "APPROXIMATE", "viewport" : { "northeast" : { "lat" : 12.0547985802915, "lng" : 99.8409453 }, "southwest" : { "lat" : 12.0521006197085, "lng" : 99.83263769999999 } } }, "place_id" : "ChIJtYNhbL8t_DARp0fnyIIkS1k", "types" : [ "natural_feature", "establishment" ] } ], "status" : "OK" }  
ภาพประจำตัวสมาชิก
M030
PHP Super Hero Member
PHP Super Hero Member
โพสต์: 532
ลงทะเบียนเมื่อ: 07/09/2015 10:06 am

Re: Google Map ไม่แสดงค่ะ (phpbb)

โพสต์ที่ยังไม่ได้อ่าน โดย M030 »

ได้แล้วค่ะ ขอบคุณมากๆนะค่ะ
ตอบกลับโพส
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: witsarutt000 และบุคลทั่วไป 52