से विशिष्ट मान प्राप्त करें मैं आयनिक/कोणीय जेएस का उपयोग कर एक ऐप बना रहा हूं। एक विशिष्ट टैब में, ऐप में स्ट्रीट नेम, स्ट्रीट नंबर इत्यादि जैसे स्वचालित रूप से कुछ फॉर्म फ़ील्ड भरने की क्षमता होती है। मेरी समस्या यह है कि, कुछ स्थितियों में उदाहरण के लिए स्ट्रीट नंबर उपलब्ध नहीं है और data[0].address_components[0].long_name
इसके बजाय सड़क नाम भरता है।आयनिक/कोणीय जेएस - रिवर्स जिओलोकेशन
.controller('PetitionsCtrl', function($scope, $cordovaGeolocation, $cordovaCamera, $log, $ionicLoading, $http, $timeout, $compile, Upload) {
$scope.getLocation = function() {
$ionicLoading.show({
templateUrl: 'loading.html',
hideOnStateChange: true
});
var posOptions = {timeout: 15000, enableHighAccuracy: true};
$cordovaGeolocation
.getCurrentPosition(posOptions)
.then(function (position) {
$scope.lat = position.coords.latitude;
$scope.lng = position.coords.longitude;
$scope.pLat = {value: $scope.lat};
$scope.pLng = {value: $scope.lng};
var geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng($scope.lat, $scope.lng);
var request = {
latLng: latlng
};
geocoder.geocode(request, function(data, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (data[0] != null) {
$scope.$apply(function() {
$scope.pStreet = {value: data[0].address_components[1].long_name};
$scope.pNumber = {value: data[0].address_components[0].long_name};
$scope.pCity = {value: data[0].address_components[2].long_name};
$scope.pAddress = {value: data[0].formatted_address};
setTimeout(function() {
$ionicLoading.hide();
}, 500);
});
} else {
$log.log("Adresa indisponibila");
setTimeout(function() {
$ionicLoading.hide();
}, 500);
}
}
})
});
};
})
यहाँ गूगल से एक उदाहरण प्रतिक्रिया है::
यहाँ कोड है कि मैं का उपयोग करें
{
"results" : [
{
"address_components" : [
{
"long_name" : "1600",
"short_name" : "1600",
"types" : [ "street_number" ]
},
{
"long_name" : "Amphitheatre Pkwy",
"short_name" : "Amphitheatre Pkwy",
"types" : [ "route" ]
},
{
"long_name" : "Mountain View",
"short_name" : "Mountain View",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Santa Clara County",
"short_name" : "Santa Clara County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "California",
"short_name" : "CA",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "94043",
"short_name" : "94043",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "1600 Amphitheatre Parkway, Mountain View, CA 94043, USA",
"geometry" : {
"location" : {
"lat" : 37.4224764,
"lng" : -122.0842499
},
"location_type" : "ROOFTOP",
"viewport" : {
"northeast" : {
"lat" : 37.4238253802915,
"lng" : -122.0829009197085
},
"southwest" : {
"lat" : 37.4211274197085,
"lng" : -122.0855988802915
}
}
},
"place_id" : "ChIJ2eUgeAK6j4ARbn5u_wAGqWA",
"types" : [ "street_address" ]
}
],
"status" : "OK"
}
मैं अपने कोड कैसे बदल सकते हैं तो यह एक पढ़ने से पहले "types"
मूल्य की जाँच करता है मूल्य उपलब्ध नहीं है और उपलब्ध नहीं होने पर इसे छोड़ देता है। अधिक संख्यात्मक होने के लिए, सड़क संख्या प्राप्त करने के लिए data[0].address_components[0].long_name
का उपयोग करने के बजाय, मैं "types"
vale "street_number"
प्राप्त करना चाहता हूं।
की तरह किसी भी अन्य मूल्य खोजने के लिए इस कोड का उपयोग कर सकते मुझे अपने आवेदन में भौगोलिक स्थान पर जाना है। जब भी मैं विशेष पृष्ठ पर जाऊंगा तो पॉप अप को भौगोलिक स्थान या से इनकार करने के लिए आना चाहिए ताकि यह कोड उस के लिए उपयोगी हो या आप मुझे सुझाव दे सकें कि इस पॉपअप को भौगोलिक स्थान की अनुमति देने के लिए कैसे जोड़ा जाए .. –
जैसा कि मैंने अपने उत्तर में कहा है, सही नहीं है क्योंकि आप सरणी पर केवल पहले तत्व की जांच कर रहे हैं। – Jorge