<!-- 获取得到的地图密匙 -->

<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);

}

};

}

更多相关文章

  1. Android(安卓)获取当前连接的WiFi信息
  2. 运用IntentService类下载文件
  3. 获取Bitmap和对Bitmap的操作工具类
  4. 从SDK的Application Fundamentals开始
  5. Android(安卓)ListView 滑到最后一条自动加载
  6. Android(安卓)camera: Metadata\Image从HAL到framework
  7. android 下获取apk的icon
  8. Android(安卓)7.0之后无摄像头调用闪关灯
  9. android 获取rom名称和版本号

随机推荐

  1. 第一章:初入Android大门(教程篇)(下)
  2. 新书内容连载(2):Android Activity的生命周
  3. Android(安卓)ImageView 的 scaleType 属
  4. (OK) 在CentOS7—编译OpenSSL 静态库—fo
  5. android 语言设置
  6. Android数据可视化
  7. Tiny4412——Android灯光系统
  8. Android富文本编辑器
  9. Android Studio 友盟多渠道打包
  10. 对Android Activity添加容错处理