|  | 
	                
  
    | 
	 
        สอบถาม แสดงพิกัดจาก google map marker ใน text box [html]     |  
    |  |  
 
	
		|  |  |  |  |  
		|  |  | 
          
            | สวัสดีครับ ผมต้องการเขียนแสดงพิกัดจาก marker บน google map ครับ ผมเขียนให้แสดงจาก search ได้แล้วและต้องการให้ เลื่อน  marker แล้วพิกัดจะแสดงจากจุด marker ครับ 
 Code (JavaScript)
 
 
function initAutocomplete() {
        var map = new google.maps.Map(document.getElementById('map'), {
            center: {lat: -33.8688, lng: 151.2195},
            zoom: 13,
            mapTypeId: 'roadmap'
        });
        // Create the search box and link it to the UI element.
        var input = document.getElementById('pac-input');
        var searchBox = new google.maps.places.SearchBox(input);
        map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);
        // Bias the SearchBox results towards current map's viewport.
        map.addListener('bounds_changed', function() {
            searchBox.setBounds(map.getBounds());
        });
        // Listen for the event fired when the user selects a prediction and retrieve
        // more details for that place.
        searchBox.addListener('places_changed', function() {
            var places = searchBox.getPlaces();
            if (places.length == 0) {
                return;
            }
            // Clear out the old markers.
            markers.forEach(function(marker) {
                marker.setMap(null);
            });
            markers = [];
            // For each place, get the icon, name and location.
            var bounds = new google.maps.LatLngBounds();
            places.forEach(function(place) {
                if (!place.geometry) {
                    console.log("Returned place contains no geometry");
                    return;
                }
                var icon = {
                    url: place.icon,
                    size: new google.maps.Size(71, 71),
                    origin: new google.maps.Point(0, 0),
                    anchor: new google.maps.Point(17, 34),
                    scaledSize: new google.maps.Size(25, 25)
                };
                // Create a marker for each place.
                markers.push(new google.maps.Marker({
                    map: map,
                    icon: icon,
                    title: place.name,
                    draggable:true,
                    animation: google.maps.Animation.DROP,
                    position: place.geometry.location
                }));
                if (place.geometry.viewport) {
                    // Only geocodes have viewport.
                    bounds.union(place.geometry.viewport);
                } else {
                    bounds.extend(place.geometry.location);
                }
                google.maps.event.addListener(markers, 'dragend', function (event) {
                    document.getElementById("latitude").value = this.getPosition().lat();
                    document.getElementById("longitude").value = this.getPosition().lng();
                });
               /* document.getElementById('latitude').value = place.geometry.location.lat();
                document.getElementById('longitude').value = place.geometry.location.lng();*/
            });
            map.fitBounds(bounds);
        });
    }
 ส่วนนี้เป็นรูปภาพครับ
 
  
 
 
 Tag : PHP, HTML, HTML5, JavaScript, jQuery
 
 
 |  
            | 
 ประวัติการแก้ไข
 2017-04-25 15:24:03
 |  
            | 
              
                |  |  |  |  
                |  | 
                    
                      | Date :
                          2017-04-24 21:14:40 | By :
                          kittipan | View :
                          1663 | Reply :
                          1 |  |  |  
                |  |  |  |  |  
            |  |  
		            |  |  
		|  |  |  |  |  |