표시되는 기존 Google지도에 마커를 추가하는 버튼을 만들려고합니다.Javascript 및 Jquery : 버튼을 클릭 할 때 Google지도에 마커 추가
function initialize()
{
geocoder = new google.maps.Geocoder();
codeAddress();
}
function codeAddress()
{
var image_icon = 'http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png';
var address = document.getElementById("type_location").value;
geocoder.geocode({ 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var mapOptions = {
zoom: 11,
center: results[0].geometry.location,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
icon: image_icon
});
}
});
}
나는 아주 새롭고 누군가 나를 도울 수 있기를 바랬다.
내지도를 표시하려면이 같은이있는 경우 :
당신$(document).ready(function() {
var coord = $(".address").attr("data-coordinates"); //this displays lat,lng (example: 32.000,-118.000)
var geocoder;
var map;
initialize();
$(".add_marker").click(function(){
// this is where I should add a marker?
});
});
예. 예. 그 안에 경고를 보내서 올바른 버튼을 클릭하고 있는지 확인하십시오. – madhairsilence
잘 작동합니까? 어떤 오류가 있습니까? 사용자가 클릭 할 때마다 새로운 맵을 생성 할 필요가 없으므로,'codeAddress' 함수 밖에서 맵을 생성 할 것을 권장합니다. – Odi