TypeError:在ajax调用和谷歌应用程序映射中未定义

时间:2015-01-05 18:56:23

标签: javascript jquery ajax google-maps

我有一个asp mvc项目,要求用户通过谷歌地图(API)进行地理定位,所以我不得不使用jquery 1.7.2并保存它的坐标,但是当我尝试通过ajax请求保存它们时我得到了这个在firebug上出错并停止所有其他代码。

http://i47.photobucket.com/albums/f195/warbandit69/ErrorKambi1_zpsac3979f4.png

正如你所看到的那样,错误与它的描述非常不相符,这里是调用jquery的函数

function ReviewAtEnd() {
        if (typeof (idserialF) != "undefined" && idserialF != null) {
            var datax = { idjob: idjobx, latitud: Latitud, longitud: Longitud, coordinates: coordenadasGM };
            var urlx = "/JOBS/PROG41/FailedItemOnSite";
            $.ajax({
                type: "POST",
                url: urlx,
                data: datax,
                async: false,
                success: function (data) {
                    mostrar_alert_ui(data.titulo, data.mensaje, 350);
                    if (data.success) {
                        AfterPassedTest();
                    }
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    alert("Failed " + urlx);
                    alert(xhr.responseText);
                    alert(thrownError);
                }
            });
        }
    }

更新

这是我错过给你看的谷歌地图功能

var Latitud;
    var Longitud;
    var coordenadasGM;
    function showMap() {

        //If HTML5 Geolocation Is Supported In This Browser
        if (navigator.geolocation) {

            //Use HTML5 Geolocation API To Get Current Position
            navigator.geolocation.getCurrentPosition(function (position) {

                //Get Latitude From Geolocation API
                var latitude = position.coords.latitude;
                Latitud = latitude;

                //Get Longitude From Geolocation API
                var longitude = position.coords.longitude;
                Longitud = Longitud;

                //Define New Google Map With Lat / Lon
                var coords = new google.maps.LatLng(latitude, longitude);
                coordenadasGM = coords;

                //Specify Google Map Options
                var mapOptions = {
                    zoom: 15,
                    center: coords,
                    mapTypeControl: true,
                    navigationControlOptions: { style: google.maps.NavigationControlStyle.SMALL }, mapTypeId: google.maps.MapTypeId.ROADMAP
                };
                map = new google.maps.Map(document.getElementById("mapContainer"), mapOptions);
                var marker = new google.maps.Marker({
                    position: coords,
                    map: map,
                    title: "You Are Here!"
                });

            }
            );

        } else {

            //Otherwise - Gracefully Fall Back If Not Supported... Probably Best Not To Use A JS Alert Though :)
            mostrar_alert_ui("WARNING", "Geolocation API is not supported in your browser.", 350)
        }

    }

    //Once Page Is Populated - Initiate jQuery
    $(document).ready(function () {

        //Show The Map
        showMap();

        // When The Viewing Window Is Resized
        $(window).resize(function () {

            //CSS Resizes Container So Lets Recall The Map Function
            showMap();

        });

    });

Jsfiddle在这里 - > http://jsfiddle.net/ricardojriosr/9mzss1ud/

0 个答案:

没有答案