개발! 딱 깔끔하고 센스있게!

php 을 어떻게 사용합니까? 본문

개발 스크랩 메모/PHP

php 을 어떻게 사용합니까?

렉사이 2020. 12. 21. 23:57

이것은 초기화 함수...

 function initialize() { 

이 변수 $Latitude, $Longitude (Longitude) 는 디지털 수치이기 때문에, Javascript 변수에 저장할 수 있습니다.

var lat=''; var lon=''; var latlng = new google.maps.LatLng(lat,lon); var myOptions = { zoom: 10, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; 

여기에서, 나는 여러 구역에서 여러 영역의 변수를 나타낼 수 있는 지리 인코더를 어떻게 순환합니까?

map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); geocoder = new google.maps.Geocoder(); var marker = new google.maps.Marker({ position: latlng, map: map, title: "Hello World!" }); } 

대답

내 예시 코드 는 영역 이름이나 lat, lng 은 Google 지도에서 여러 영역을 그립니다.

 var map; var geocoder; var marker; var people = new Array(); var latlng; var infowindow; $(document).ready(function() { ViewCustInGoogleMap(); }); function ViewCustInGoogleMap() { var mapOptions = { center: new google.maps.LatLng(11.0168445, 76.9558321), // Coimbatore = (11.0168445, 76.9558321) zoom: 7, mapTypeId: google.maps.MapTypeId.ROADMAP }; map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions); // Get data from database. It should be like below format or you can alter it. var data = '[{ "DisplayText": "adcv", "ADDRESS": "Jamiya Nagar Kovaipudur Coimbatore-641042", "LatitudeLongitude": "10.9435131,76.9383790", "MarkerId": "Customer" },{ "DisplayText": "abcd", "ADDRESS": "Coimbatore-641042", "LatitudeLongitude": "11.0168445,76.9558321", "MarkerId": "Customer"}]'; people = JSON.parse(data); for (var i = 0; i < people.length; i++) { setMarker(people[i]); } } function setMarker(people) { geocoder = new google.maps.Geocoder(); infowindow = new google.maps.InfoWindow(); if ((people["LatitudeLongitude"] == null) || (people["LatitudeLongitude"] == 'null') || (people["LatitudeLongitude"] == '')) { geocoder.geocode({ 'address': people["Address"] }, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { latlng = new google.maps.LatLng(results[0].geometry.location.lat(), results[0].geometry.location.lng()); marker = new google.maps.Marker({ position: latlng, map: map, draggable: false, html: people["DisplayText"], icon: "images/marker/" + people["MarkerId"] + ".png" }); //marker.setPosition(latlng); //map.setCenter(latlng); google.maps.event.addListener(marker, 'click', function(event) { infowindow.setContent(this.html); infowindow.setPosition(event.latLng); infowindow.open(map, this); }); } else { alert(people["DisplayText"] + " -- " + people["Address"] + ". This address couldn't be found"); } }); } else { var latlngStr = people["LatitudeLongitude"].split(","); var lat = parseFloat(latlngStr[0]); var lng = parseFloat(latlngStr[1]); latlng = new google.maps.LatLng(lat, lng); marker = new google.maps.Marker({ position: latlng, map: map, draggable: false, // cant drag it html: people["DisplayText"] // Content display on marker click //icon: "images/marker.png" // Give ur own image }); //marker.setPosition(latlng); //map.setCenter(latlng); google.maps.event.addListener(marker, 'click', function(event) { infowindow.setContent(this.html); infowindow.setPosition(event.latLng); infowindow.open(map, this); }); } }
   
Comments