Google map ไม่ search ตามสถานที่ที่ต้องการ

สำหรับผู้ที่ เริ่มต้น 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 ไม่ search ตามสถานที่ที่ต้องการ

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

Google map ไม่ search ตามสถานที่ที่ต้องการ
ตอนนี้เปลี่ยนมาใช้ api google map แบบ javascript ค่ะ เช่นเรา search ภูเก็ต มันยังขึ้น dm, อยุ่ค่ะ

code ***.php

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

 $address = request_var('address', '', true);

                $address = $subdistrict;
                $province_add = $province;
                $zipcodes_add = $zipcode;

                $api = 'AIzaSyBuNORhP8fRDljXWbfvDKBN6D6UWVfxV14';
                $add = $address.=$province.=$zipcode; //  $address = เสนานิคม เราสามารถ Get หรือ ทำเป็นฟอร์มรับค่ามาก่อนได้

                    $latitude = 13.7246005;
                    $longitude = 100.6331108;
                   // $formatted_address = $resp['results'][0]['formatted_address'];
                
                $this->template->assign_block_vars('m_map_subdistrict', array(
                    'LATITUDE' => $latitude,
                    'LONGITUDE' => $longitude,
                    'FORMATTED_ADDRESS' => $formatted_address,
                     'API_KEY'=> $api,
                    'ADDRESS'=>$add,
                ));
code ***.html

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

 <script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
 <script>
function initialize() {
    var myLatlng = new google.maps.LatLng("{m_map_subdistrict.LATITUDE}", "{m_map_subdistrict.LONGITUDE}");
    var mapOptions = {zoom : 8, center : myLatlng};
    var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

    var contentString = '<div style="font-size: 18px;">{m_map_subdistrict.ADDRESS}</div>';

    var infowindow = new google.maps.InfoWindow({
        content : contentString
    });
    var marker = new google.maps.Marker({
        position : myLatlng,
        map : map,
       
    });
    google.maps.event.addListener(marker, 'click', function() {
        infowindow.open(map, marker);
    });
}
    google.maps.event.addDomListener(window, 'load', initialize);
</script>
phuket.png
phuket.png (175.9 KiB) Viewed 1581 times
ภาพประจำตัวสมาชิก
tsukasaz
PHP VIP Members
PHP VIP Members
โพสต์: 21991
ลงทะเบียนเมื่อ: 18/04/2012 9:39 am

Re: Google map ไม่ search ตามสถานที่ที่ต้องการ

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

ตัวอย่างค้นหาตามชื่อสถานที่ครับ

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

<!DOCTYPE html>
<html>
	<head>
		<title>Place details</title>
		<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
		<meta charset="utf-8">
		<style>
			html, body {
				height: 100%;
				margin: 0;
				padding: 0;
			}
			#map {
				height: 100%;
			}
		</style>

	</head>
	<body>
		<div id="map"></div>
		<script
		src="https://maps.googleapis.com/maps/api/js?callback=initMap" async defer></script>
		<script>
			function initMap() {
				var map = new google.maps.Map(document.getElementById('map'), {zoom: 15});

				var geocoder = new google.maps.Geocoder();
				geocoder.geocode({'address': 'บางพูด ปากเกร็ด นนทบุรี'}, function (results, status) {
					if (status === google.maps.GeocoderStatus.OK) {
						map.setCenter(results[0].geometry.location);
						var marker = new google.maps.Marker({
							map: map,
							position: results[0].geometry.location
						});
					} else {
						alert('Geocode was not successful for the following reason: ' + status);
					}

				});
			}

		</script>
	</body>
</html>
The last bug isn't fixed until the last user is dead. (Sidney Markowitz, 1995)
ภาพประจำตัวสมาชิก
M030
PHP Super Hero Member
PHP Super Hero Member
โพสต์: 532
ลงทะเบียนเมื่อ: 07/09/2015 10:06 am

Re: Google map ไม่ search ตามสถานที่ที่ต้องการ

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

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

Re: Google map ไม่ search ตามสถานที่ที่ต้องการ

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

tsukasaz เขียน:ตัวอย่างค้นหาตามชื่อสถานที่ครับ

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

<!DOCTYPE html>
<html>
	<head>
		<title>Place details</title>
		<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
		<meta charset="utf-8">
		<style>
			html, body {
				height: 100%;
				margin: 0;
				padding: 0;
			}
			#map {
				height: 100%;
			}
		</style>

	</head>
	<body>
		<div id="map"></div>
		<script
		src="https://maps.googleapis.com/maps/api/js?callback=initMap" async defer></script>
		<script>
			function initMap() {
				var map = new google.maps.Map(document.getElementById('map'), {zoom: 15});

				var geocoder = new google.maps.Geocoder();
				geocoder.geocode({'address': 'บางพูด ปากเกร็ด นนทบุรี'}, function (results, status) {
					if (status === google.maps.GeocoderStatus.OK) {
						map.setCenter(results[0].geometry.location);
						var marker = new google.maps.Marker({
							map: map,
							position: results[0].geometry.location
						});
					} else {
						alert('Geocode was not successful for the following reason: ' + status);
					}

				});
			}

		</script>
	</body>
</html>
ลองนำโค้ดมาใส่ดูแล้วค่ะ แต่ google map ยังไม่แสดงเลยค่ะ

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

 <script
      src="https://maps.googleapis.com/maps/api/js?callback=initialize" async defer></script>
  <!-- BEGIN m_map_subdistrict -->  
 <script>
function initialize() {
    var myLatlng = new google.maps.LatLng("{m_map_subdistrict.LATITUDE}", "{m_map_subdistrict.LONGITUDE}");
    var mapOptions = {zoom : 5, center : myLatlng};
    var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
    var marker = new google.maps.Marker({
        map: map,
                position: new google.maps.LatLng( "{m_map_subdistrict.LATITUDE}" , "{m_map_subdistrict.LONGITUDE}")
        });

    var contentString = "{m_map_subdistrict.DISTRICT_ADD}";
    var geocoder = new google.maps.Geocoder();
            geocoder.geocode({'address': 'บางพูด ปากเกร็ด นนทบุรี'}, function (results, status) {
               if (status === google.maps.GeocoderStatus.OK) {
                  map.setCenter(results[0].geometry.location);
                  var marker = new google.maps.Marker({
                     map: map,
                     position: results[0].geometry.location
                  });
               } else {
                  alert('Geocode was not successful for the following reason: ' + status);
               }
               });
    var infowindow = new google.maps.InfoWindow({
        content : contentString
    });
   
    google.maps.event.addListener(marker, 'click', function() {
        infowindow.open(map, marker);
    });
}
    google.maps.event.addDomListener(window, 'load', initialize);
</script>

<div id="map-canvas" style="width:750px;  height:500px;  margin-left: 200px;  margin-top:60px;"></div>
 <!-- END m_map_subdistrict --> 
    
ภาพประจำตัวสมาชิก
M030
PHP Super Hero Member
PHP Super Hero Member
โพสต์: 532
ลงทะเบียนเมื่อ: 07/09/2015 10:06 am

Re: Google map ไม่ search ตามสถานที่ที่ต้องการ

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

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

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

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