net使用javascript,我从谷歌地图中获取了如何将数据保存到数据库中 var地理编码器; if(导航器.地理位置){ navigator.geolocation.getCurrentPosition(successFunction,errorFunction); } //得到纬度和经度; 功能成功功能(位置){ var lat=位置坐标纬度; var lng=位置坐标经度; codeLatLng(lat,lng) } 函数errorFunction(){ 警报(“地理编码器失败”); } 函数初始化(){ geocoder=新的google.maps.geocoder(); } 功能代码LATLNG(lat,lng){ var latlng=新的google.maps.latlng(lat,lng); 变量映射选项={ 缩放:15, 中心:拉特林, mapTypeControl:true, 导航控制选项: { 样式:google.maps.NavigationControlStyle.SMALL }, mapTypeId:google.maps.mapTypeId.ROADMAP }; map=新建google.maps.map( document.getElementById(“mapContainer”),mapOptions ); geocoder.geocode({'latLng':latLng},函数(结果,状态){ if(status==google.maps.GeocoderStatus.OK){ console.log(结果) 如果(结果[1]){ //格式化地址 警报(结果[0]。格式化的\u地址) //查找国家名称 对于(var i=0;i

net使用javascript,我从谷歌地图中获取了如何将数据保存到数据库中 var地理编码器; if(导航器.地理位置){ navigator.geolocation.getCurrentPosition(successFunction,errorFunction); } //得到纬度和经度; 功能成功功能(位置){ var lat=位置坐标纬度; var lng=位置坐标经度; codeLatLng(lat,lng) } 函数errorFunction(){ 警报(“地理编码器失败”); } 函数初始化(){ geocoder=新的google.maps.geocoder(); } 功能代码LATLNG(lat,lng){ var latlng=新的google.maps.latlng(lat,lng); 变量映射选项={ 缩放:15, 中心:拉特林, mapTypeControl:true, 导航控制选项: { 样式:google.maps.NavigationControlStyle.SMALL }, mapTypeId:google.maps.mapTypeId.ROADMAP }; map=新建google.maps.map( document.getElementById(“mapContainer”),mapOptions ); geocoder.geocode({'latLng':latLng},函数(结果,状态){ if(status==google.maps.GeocoderStatus.OK){ console.log(结果) 如果(结果[1]){ //格式化地址 警报(结果[0]。格式化的\u地址) //查找国家名称 对于(var i=0;i,javascript,c#,asp.net,google-maps-api-3,Javascript,C#,Asp.net,Google Maps Api 3,2-3个小时,我在互联网上搜索并尝试,但没有得到结果。我正在尝试另一个代码块,纬度和经度可以保存数据库。这不仅仅是我想要的,我想保存城市格式的地址 我在另一个论坛上发表了这个问题,没有回应。 我需要很多帮助。代码可能会在这里出现。本期作业项目。这与sql server无关。请正确使用标记这与sql server无关。请正确使用标签 <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDX1D37MapC2HfewVE

2-3个小时,我在互联网上搜索并尝试,但没有得到结果。我正在尝试另一个代码块,纬度和经度可以保存数据库。这不仅仅是我想要的,我想保存城市格式的地址

我在另一个论坛上发表了这个问题,没有回应。
我需要很多帮助。代码可能会在这里出现。本期作业项目。

这与sql server无关。请正确使用标记这与sql server无关。请正确使用标签
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDX1D37MapC2HfewVE0T3MXcUT4bstvHq8&callback=initMap" type="text/javascript"></script>
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript">

    var geocoder;
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(successFunction, errorFunction);
    }
    //Get the latitude and the longitude;
    function successFunction(position) {
        var lat = position.coords.latitude;
        var lng = position.coords.longitude;
        codeLatLng(lat, lng)
    }

    function errorFunction() {
        alert("Geocoder failed");
    }

    function initialize() {
        geocoder = new google.maps.Geocoder();
    }

    function codeLatLng(lat, lng) {

        var latlng = new google.maps.LatLng(lat, lng);
        var mapOptions = {
            zoom: 15,
            center: latlng,
            mapTypeControl: true,
            navigationControlOptions:
                {
                    style: google.maps.NavigationControlStyle.SMALL
                },
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        map = new google.maps.Map(
                     document.getElementById("mapContainer"), mapOptions
                     );
        geocoder.geocode({ 'latLng': latlng }, function (results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                console.log(results)
                if (results[1]) {
                    //formatted address
                    alert(results[0].formatted_address)
                    //find country name
                    for (var i = 0; i < results[0].address_components.length; i++) {
                        for (var b = 0; b < results[0].address_components[i].types.length; b++) {
                            //there are different types that might hold a city admin_area_lvl_1 usually does in come cases looking for sublocality type will be more appropriate
                            if (results[0].address_components[i].types[b] == "administrative_area_level_1") {
                                //this is the object you are looking for
                                city = results[0].address_components[i];
                                break;
                            }
                        }
                    }
                    // city data                  
                    alert(city.short_name + " " + city.long_name)
                }
                else {
                    alert("No results found");
                }
            }
            else {
                alert("Geocoder failed due to: " + status);
            }
            var marker = new google.maps.Marker({
                position: latlng,
                map: map,
                title: "Your Location"
            });
        });
    }
</script>