// google geolocation
googleMap: function(func){
if (navigator.geolocation) {
//get location
navigator.geolocation.getCurrentPosition(function(position) {
var coords = position.coords;
lat = coords.latitude;
lng = coords.longitude;
var latlng = new google.maps.LatLng(lat, lng);
var geocoder = new google.maps.Geocoder();
geocoder.geocode( {'location': latlng}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var time = Date.parse(new Date());
var resultArr = results[0].address_components, address = "" ,LocationName = "",province = "",city = "",district = "";
for (var i = 0; i < resultArr.length; i++) {
var type = resultArr[i].types[0] ? resultArr[i].types[0] : 0;
if (type && type == "street_number") {
LocationName = resultArr[i].short_name;
}
if (type && type == "route") {
address = address + resultArr[i].short_name;
}
if (type && type == "political") {
district = resultArr[i].short_name;
}
if (type && type == "locality") {
city = resultArr[i].short_name;
}
if (type && type == "administrative_area_level_1") {
province = resultArr[i].short_name;
}
}
var data = {'name': LocationName + ' ' + address, 'address': address, 'lng': lng, 'lat': lat, 'province': province, 'city': city, 'district': district};
func(data);
} else {
func();
alert('Geocode was not successful for the following reason: ' + status);
}
});
}, function getError(error){
func();
switch(error.code){
case error.TIMEOUT:
alert(langData['siteConfig'][22][100]);
break;
case error.PERMISSION_DENIED:
alert(langData['siteConfig'][22][101]);
break;
case error.POSITION_UNAVAILABLE:
alert(langData['siteConfig'][22][102]);
break;
default:
break;
}
})
}else {
func();
alert(langData['waimai'][3][72])
}
},
h5: function(func){
if (navigator.geolocation) {
if ("function" == typeof func) {
h5LocationInit.fn = func
}
window.touchH5LocationCallback = function(f, g) {
if(f == null){
HN_Location.getLocationByGeocoding(g);
}else{
// getLocationError(f);
HN_Location.init(func, true);
}
$("#touchH5LocationIframe").remove();
},
$('<iframe src="javascript:(function(){ window.navigator.geolocation.getCurrentPosition(function(position){parent && parent.touchH5LocationCallback && parent.touchH5LocationCallback(null,position);}, function(err){parent && parent.touchH5LocationCallback && parent.touchH5LocationCallback(err);}, {enableHighAccuracy: 1, maximumAge: 10000, timeout: 5000});})()" style="display:none;" id="touchH5LocationIframe" ></iframe>').appendTo("body")
} else {
// var r = {
// tips: "broswer not supported"
// };
// "function" == typeof func ? func(r) : "[object Object]" === Object.prototype.toString.call(func) && func.fn && func.fn(r)
HN_Location.init(func, true);
}
},