我有插入位置的代码,并在谷歌地图上标记:
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script>
var geocoder;
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(52.243240, 21.030295);
var mapOptions = {
zoom: 8,
center: latlng
}
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
}
function codeAddress() {
var address = document.getElementById('address').value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
var input = results[0].geometry.location;
document.getElementById("wypisz").innerHTML=input;
//document.getElementById("wypisz").innerHTML = results[0].geometry.location.lng;
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
// document.write(position);
</script>
在这2行中,我获取了我的位置坐标“(52.1553949,21.07453620000001)”,并在页面上显示:
var input = results[0].geometry.location;
document.getElementById("wypisz").innerHTML=input;
我不能做的是在2个子串(lat和lng)上拆分字符串“input”,并将其保存到Mysql DB,使用lat和lng(两个浮点类型)保存到表中。