2016-07-29 2 views
0

Google지도에서 새로운 기능입니다. 이 코드를 사용하여 Google지도를 표시합니다.Google지도에서 위치를 얻고 표시 할 수있는 방법

<!DOCTYPE html> 
<html> 
<head> 
<script src="http://maps.googleapis.com/maps/api/js"></script> 
<script> 
function initialize() { 
    var mapProp = { 
    center:new google.maps.LatLng(32.39793603710494,51.39232635498047), 
    zoom:5, 
    mapTypeId:google.maps.MapTypeId.ROADMAP 
    }; 
    var map=new google.maps.Map(document.getElementById("googleMap"),mapProp); 
} 
google.maps.event.addDomListener(window, 'load', initialize); 
</script> 
</head> 

<body> 
<div id="googleMap" style="width:500px;height:380px;"></div> 
</body> 

</html> 

가 지금은 표시하고 위도 및 경도 내가 그것을 클릭 장소 싶어, 나는 database.How에 내가 그렇게 할 수 저장을 위해 위도 및 경도를 원?

+0

가능한 중복 (http://stackoverflow.com/questions/27307110/cant-add-markers-to-custom-tile -map) – geocodezip

+0

가능한 중복 [어떻게 사용자 정의 할 수 있고 공유가 가능한 colaborative 맵을 만들 수 있습니까?] (http://stackoverflow.com/questions/19015842/how-can-i-create-a-custom-shareable-and- colaborative-map) – geocodezip

+0

[Google Maps에서 PHP/MySQL 사용하기] (https://developers.google.com/maps/articles/phpsqlajax_v3) – geocodezip

답변

2

나는 두 가지 지적한 질문 모두에서 관련 ans를 볼 수 없기 때문에 내 대답을했습니다.

var map = new google.maps.Map(document.getElementById('map_canvas'), { 
     zoom: 1, 
     center: new google.maps.LatLng(35.137879, -82.836914), 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }); 

var myMarker = new google.maps.Marker({ 
    position: new google.maps.LatLng(47.651968, 9.478485), 
    draggable: true 
}); 

google.maps.event.addListener(myMarker, 'dragend', function (evt) { 
// from here you can get where point marker user put and get that let long using 
// Lat = evt.latLng.lat().toFixed(3) 
// Lng = evt.latLng.lng().toFixed(3) 
// after this you can do ajax call and save at you server and do what ever you wanted to do ... 

    document.getElementById('current').innerHTML = '<p>Marker dropped: Current Lat: ' + evt.latLng.lat().toFixed(3) + ' Current Lng: ' + evt.latLng.lng().toFixed(3) + '</p>'; 
}); 

google.maps.event.addListener(myMarker, 'dragstart', function (evt) { 
    document.getElementById('current').innerHTML = '<p>Currently dragging marker...</p>'; 
}); 

map.setCenter(myMarker.position); 
myMarker.setMap(map); 

html 

<body> 
    <section> 
     <div id='map_canvas'></div> 
     <div id="current">Nothing yet...</div> 
    </section> 
</body> 

작업 데모 : [캔트 사용자 정의 타일지도에 마커를 추가]의 link

관련 문제