Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在数据库中插入经纬度_Javascript_Php_Html_Google Maps - Fatal编程技术网

Javascript 在数据库中插入经纬度

Javascript 在数据库中插入经纬度,javascript,php,html,google-maps,Javascript,Php,Html,Google Maps,我目前正在编写一个代码,当用户输入位置时,他将获得纬度n经度,但我需要向数据库添加纬度和经度。客户端代码正在工作。下面给出了html文件 如何在php中为服务器端传输这些值并将其添加到数据库中 <!DOCTYPE html> <html> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no"> <meta c

我目前正在编写一个代码,当用户输入位置时,他将获得纬度n经度,但我需要向数据库添加纬度和经度。客户端代码正在工作。下面给出了html文件

如何在php中为服务器端传输这些值并将其添加到数据库中

    <!DOCTYPE html>
    <html>
    <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="UTF-8">
    <title>maps</title>
     <style>
     #map_canvas { width:400px; height:450px; }
      </style>
     <script type="text/javascript" src="http://maps.google.com/maps/api/js?                   sensor=false">
     </script>
     <script type="text/javascript">

      var geocoder;
      var map;
      var lat;
      var lng;

       function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-30.070, -51.190);
var myOptions = {
    zoom: 9,
    center: latlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}

    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;
        document.getElementById('lat').value = results[0].geometry.location.lat();
        document.getElementById('lng').value = results[0].geometry.location.lng();


    } else {
        alert("Geocode was not successful for the following reason: " + status);
    }
});
  }



   </script>
    </head>

    <body onload="initialize()">
    <form action="map2.php" method="get">

 <div id="map_canvas"></div>
 <div>
    <input id="address" type="textbox" value="">
    <input type="button" value="Localizar!" onclick="codeAddress()"><br>
    Latitude: <input type="text" id="lat"><br>
    Longitude: <input type="text" id="lng"><br>
 </div>

地图
#地图画布{宽度:400px;高度:450px;}
var地理编码器;
var映射;
var lat;
乏液化天然气;
函数初始化(){
geocoder=新的google.maps.geocoder();
var-latlng=new google.maps.latlng(-30.070,-51.190);
变量myOptions={
缩放:9,
中心:拉特林,
mapTypeId:google.maps.mapTypeId.ROADMAP
}
map=new google.maps.map(document.getElementById(“map_canvas”),myOptions);
}
函数代码地址(){
var address=document.getElementById(“地址”).value;
geocoder.geocode({'address':address},函数(结果,状态){
if(status==google.maps.GeocoderStatus.OK){
map.setCenter(结果[0].geometry.location);
var marker=new google.maps.marker;
document.getElementById('lat')。value=results[0]。geometry.location.lat();
document.getElementById('lng')。value=results[0]。geometry.location.lng();
}否则{
警报(“地理编码因以下原因未成功:“+状态”);
}
});
}

纬度:
经度:

您可以使用jquery轻松完成这项工作(无需页面加载或表单提交)-

在php文件中:

  <?php
    // file name: your-php-code-url-to-save-in-database.php
   $lat=$_POST['lat'];
   $lng=$_POST['lng'];

   // write your insert query here to save $lat and $lng 


  ?>

要了解更多信息并下载Jquery,请访问:

另一种方法是不使用Jquery(页面将重定向到map2.php):



纬度:
经度:
在map2.php中编写-

 <?php

     // file name: map2.php

   $lat=$_GET['lat'];
   $lng=$_GET['lng'];

   // write your insert query here to save $lat and $lng 
   //get your mysql db connection ready

    $sql="insert into table_name (latitude, longitude) values('".$lat."','".$lng.")";
    $command=mysql_query($sql);

    // close databse connection  and everythig is done then redict to any page.
    //check your database table to see the inserted value

  ?>

您可以使用jquery轻松完成这项工作(无需页面加载或表单提交)-

在php文件中:

  <?php
    // file name: your-php-code-url-to-save-in-database.php
   $lat=$_POST['lat'];
   $lng=$_POST['lng'];

   // write your insert query here to save $lat and $lng 


  ?>

要了解更多信息并下载Jquery,请访问:

另一种方法是不使用Jquery(页面将重定向到map2.php):



纬度:
经度:
在map2.php中编写-

 <?php

     // file name: map2.php

   $lat=$_GET['lat'];
   $lng=$_GET['lng'];

   // write your insert query here to save $lat and $lng 
   //get your mysql db connection ready

    $sql="insert into table_name (latitude, longitude) values('".$lat."','".$lng.")";
    $command=mysql_query($sql);

    // close databse connection  and everythig is done then redict to any page.
    //check your database table to see the inserted value

  ?>

hey thanx谢谢你的帮助,但我是用php做的,只有5-6行代码..非常感谢:)hey thanx谢谢你的帮助,但我是用php做的,只有5-6行代码..非常感谢:)