在我的应用程序中,我想获取纬度和经度值。我有以下代码。它在第一次调用该函数时崩溃。应用程序询问用户使用当前位置的权限,应用程序崩溃抛出空引用异常,我将纬度值分配给字符串
string getLocation()
{
string latlong = "|";
CLLocationManager locationManager = new CLLocationManager();
locationManager.StartUpdatingLocation();
//var locationVar = locationManager.Location.Coordinate;
string lat = locationManager.Location.Coordinate.Latitude.ToString();
string lon = locationManager.Location.Coordinate.Longitude.ToString();
latlong = lat + "|" + lon;
return latlong;
}