私は現在の経度と緯度を取得し、それをデータベースに保存する必要があるJavaスクリプトでGoogleマップを使用しています、トリックはどのようにドラッグ可能です私は現在の長いと緯度を得ることができますか?JavaScriptのgoogle mapsの経度と緯度を取得する方法
function markernew(){
markers = [];
//var val=document.getElementById('val2').value=;
$("#floating-panel").show();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 1,
center: latlng,
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
navigationControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);
if(marker) marker.setMap(null);
var geocoder;
var address ="";
if(!document.getElementById('address_id').value){
alert('Enter Address');
}
else if (!document.getElementById('city_id').value){
alert('Enter City');
}
else if (!document.getElementById('nearby_id').value){
alert('Enter Country');
}
else{
$("#findplace").show();
var address="";
var array = document.getElementById('address_id').value;
array+=",";
if(array.match(/,/g).length==1){
array = array.split(',');
address += array[0]+" ";
address += array[1];
}
else if(array.match(/,/g).length==2){
array = array.split(',');
address += array[0]+" ";
address += array[1]+" ";
address += array[2];
}
else if(array.match(/,/g).length==3){
array = array.split(',');
address += array[0]+" ";
address += array[1]+" ";
address += array[2]+" ";
address += array[3];
}
else if(array.match(/,/g).length==4){
array = array.split(',');
address += array[0]+" ";
address += array[1]+" ";
address += array[2]+" ";
address += array[3]+" ";
address += array[4];
}
else if(array.match(/,/g).length==5){
array = array.split(',');
address += array[0]+" ";
address += array[1]+" ";
address += array[2]+" ";
address += array[3]+" ";
address += array[4]+" ";
address += array[5];
}
else{
alert("inside else");
var address= document.getElementById('address_id').value;
}
// address += document.getElementById('address_id').value + " ";
address += document.getElementById('city_id').value + " ";
address += document.getElementById('nearby_id').value;
geocoder = new google.maps.Geocoder();
if (geocoder) {
geocoder.geocode({ 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
map.setCenter(results[0].geometry.location);
map.setZoom(15);
var infowindow = new google.maps.InfoWindow(
{ content: '<b>'+address+'</b>',
size: new google.maps.Size(150,50)
});
google.maps.event.addListener(map, 'click', function(event) {
if(abc==true){
placeMarker(event.latLng);
abc=false;
}
});
} else {
alert("No results found");
}
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
}
}
function placeMarker(location) {
var marker = new google.maps.Marker({
position: location,
map: map,
draggable:true
});
markers.push(marker);
var infowindow = new google.maps.InfoWindow({
content: 'Latitude: ' + location.lat() + '<br>Longitude: ' + location.lng()
});
infowindow.open(map,marker);
}
function setMapOnAll(map) {
for (var i = 0; i < markers.length; i++) {
markers[i].setMap(map);
}
}
function clearMarkers() {
setMapOnAll(null);
}
function deleteMarkers() {
clearMarkers();
abc=true;
markers = [];
}
navigator.geolocaを使用して試すことができます –
私たちが試すことができるレポはありますか? – noogui