Created
March 15, 2013 04:25
-
-
Save tychio/5167476 to your computer and use it in GitHub Desktop.
get province and city
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
/* @param get callback for province and city | |
/* @param lat latitude | |
/* @param lng longitude | |
**/ | |
function getPosition (get, lat, lng) { | |
if (lat === undefined) {//auto get, if lat and lng was undefined | |
if (navigator.geolocation) {//html 5 geolocation | |
navigator.geolocation.getCurrentPosition(function (p_pos) { | |
getPosition(get, p_pos.coords.latitude, p_pos.coords.longitude); | |
}); | |
} else {//sina api | |
$.getScript('http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js', function () { | |
get(remote_ip_info.province, remote_ip_info.city); | |
}) | |
} | |
} else {//tencent soso map | |
var center = new soso.maps.LatLng(lat, lng); | |
map = new soso.maps.Map(document.getElementById('container'),{ | |
center: center, | |
zoomLevel: 13 | |
}); | |
geocoder = new soso.maps.Geocoder(); | |
var latLng = new soso.maps.LatLng(lat, lng); | |
var info = new soso.maps.InfoWindow({map: map}); | |
geocoder.geocode({'location': latLng}, function(results, status) { | |
if (status == soso.maps.GeocoderStatus.OK) { | |
get(results.addressComponents.province, results.addressComponents.city); | |
} else { | |
get(false, status); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment