0
我有以下角文字。我面臨的問題是我在http請求的成功方法中收到的數據的數據類型。已經收到的數據用於在google地圖上顯示當前位置,使用可用的javascript。問題是,位置標記和地圖沒有顯示經度和緯度。但是,如果我硬編碼並通過靜態值(靜態輸入評論),地圖和位置標記正在顯示。請幫我解決這個問題。提前致謝。
var app = angular.module("myApp", []);
app.controller("myCtrl",function ($scope,$rootScope,$http) {
var city = 'Mumbai';
$scope.uploadResultFinal= false;
$http({
method: 'POST',
url: '\HomeServlet2',
headers: {
'Content-Type': 'application/json'
},
params: {
City:city
}
});
.success(function(data) {
console.log(angular.toJson(data));
$scope.data1= data.Addresses;
$scope.latlang =[$scope.data1[2].Latitude,$scope.data1[2].Longitude];
$scope.uploadResultFinal= true;
})
.error(function(data, status, header, config) {
console.log('Error');
});
$scope.$watch('uploadResultFinal', function() {
alert($scope.latlang[0]);
alert($scope.latlang[1]);
var l1 =$scope.latlang[0];
var l2 =$scope.latlang[1];
/* static values are commented.*/
/*
var l1= "19.72";
var l2= "72.63";
*/
var myCenter=new google.maps.LatLng(l1,l2);
function initialize() {
var mapProp = {
center:myCenter,
zoom:5,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
var marker=new google.maps.Marker({
position:myCenter,
animation:google.maps.Animation.BOUNCE
});
marker.setMap(map);
var infowindow = new google.maps.InfoWindow({
content:"You Are Here!"
});
infowindow.open(map,marker);
}
google.maps.event.addDomListener(window, 'load', initialize);
},true);
}
);