googlemap学习
<!-- 获取得到的地图密匙 -->
<com.google.android.maps.MapView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="0EGaQ0LojZADsSw-E2Nh0NIYkPuTgNKFSmvHWsA"
/>
package my.yaner.googlemap;
import my.yaner.R;
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.TextView;
/**
* google地图搜索应用启动类
* @author Administrator
* 通过调用andorid自带的API实现地域的查询
*/
public class GoogleMapStartActivity extends Activity {
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.googlemap);
init();
}
private void init() {
String serviceString = Context.LOCATION_SERVICE;
LocationManager locationManager = (LocationManager) getSystemService(serviceString);
String provider = LocationManager.GPS_PROVIDER;
Location location = locationManager.getLastKnownLocation(provider); //获取当前的位置信息
getLocationInfo(location);
locationManager.requestLocationUpdates(provider, 2000, 0, locationListener);
}
private void getLocationInfo(Location location) {
String latLongInfo;
TextView locationText = (TextView) findViewById(R.id.google_str_textview);
if(location != null){
double lat = location.getLatitude();
double lng = location.getLongitude();
latLongInfo = "Lat: " + lat + " ,nLong: " + lng;
}else{
latLongInfo = "no location found";
}
locationText.setText("您当前所在的位置是:" + latLongInfo);
}
private LocationListener locationListener = new LocationListener() {
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
getLocationInfo(null);
}
@Override
public void onProviderDisabled(String provider) {
getLocationInfo(null);
}
@Override
public void onLocationChanged(Location location) {
getLocationInfo(location);
}
};
}
更多相关文章
- Android(安卓)获取当前连接的WiFi信息
- 运用IntentService类下载文件
- 获取Bitmap和对Bitmap的操作工具类
- 从SDK的Application Fundamentals开始
- Android(安卓)ListView 滑到最后一条自动加载
- Android(安卓)camera: Metadata\Image从HAL到framework
- android 下获取apk的icon
- Android(安卓)7.0之后无摄像头调用闪关灯
- android 获取rom名称和版本号