要查找当前位置,您需要安装cordova geolocation插件,然后使用以下代码
function CheckCurrentLocation(){
if( navigator.geolocation ) {
var options={maximumAge:60000, timeout:5000, enableHighAccuracy:true };
navigator.geolocation.getCurrentPosition( success, fail);
}
else { alert("Sorry, your browser does not support geolocation services."); } }
function success(position) {
alert( "latitude :"+position.coords.latitude +", longititude : "+position.coords.longitude);
var userLatLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
writeAddressName(userLatLng);
function writeAddressName(userLatLng) {
var geocoder = new google.maps.Geocoder();
geocoder.geocode({
"location": userLatLng
},
function(results,