googlemapapiv2地图导航Word下载.docx
- 文档编号:5204874
- 上传时间:2023-05-04
- 格式:DOCX
- 页数:24
- 大小:280.91KB
googlemapapiv2地图导航Word下载.docx
《googlemapapiv2地图导航Word下载.docx》由会员分享,可在线阅读,更多相关《googlemapapiv2地图导航Word下载.docx(24页珍藏版)》请在冰点文库上搜索。
//位置信息更新时调用
publicvoid
onLocationChanged(Locationlocation)
{
if(location!
=null)
Toast.makeText(getBaseContext(),
"
Newlocationlatitude["
+
location.getLatitude()+
]longitude["
location.getLongitude()+"
]"
Toast.LENGTH_SHORT).show();
}
//当禁用的提供程序被调用时会立即调用
onProviderDisabled(Stringprovider)
//用户启用提供程序时被调用
onProviderEnabled(Stringprovider)
//状态变化时被调用
onStatusChanged(Stringprovider,
intstatus,Bundleextras)
};
startActivityForResult(newIntent(android.provider.Settings.ACTION_LOCALE_SETTINGS),0);
//请求用户打开GPS
/**
LocationManager接近提醒
*/
//geo模式:
用uri的前缀来过滤数据类型
StringPROX_ALERT="
com.androidbook.intent.action.PROXIMITY_ALERT"
;
IntentFilteriFilter=newIntentFilter(PROX_ALERT);
//设置了过滤器所接受的行为
iFilter.addDataScheme("
geo"
);
//设置了过滤器说接受的uri前缀
Stringgeo="
geo:
"
+lat+"
"
+lon;
Intentintent=newIntent(PROX_ALERT,Uri.parse(geo));
//在intent中添加uri匹配intentFilter
pIntent1=PendingIntent.getBroadcast(getApplicationContext(),0,intent,
PendingIntent.FLAG_CANCEL_CURRENT);
//创建PendingIntent
locMgr.addProximityAlert(lat,lon,radius,6000L,pIntent1);
//纬度,经度,半径,超时,触发后的行为
AndroidManifest.xml
<
?
xmlversion="
1.0"
encoding="
utf-8"
>
manifestxmlns:
android="
package="
com.example.v2_test"
android:
versionCode="
1"
versionName="
>
<
uses-sdk
minSdkVersion="
8"
targetSdkVersion="
17"
/>
permission
name="
com.example.v2_test.permission.MAPS_RECEIVE"
protectionLevel="
signature"
uses-permissionandroid:
android.permission.INTERNET"
android.permission.WRITE_EXTERNAL_STORAGE"
com.google.android.providers.gsf.permission.READ_GSERVICES"
android.permission.ACCESS_COARSE_LOCATION"
android.permission.ACCESS_FINE_LOCATION"
android.permission.ACCESS_MOCK_LOCATION"
/>
uses-feature
glEsVersion="
0x00020000"
required="
true"
application
allowBackup="
icon="
@drawable/ic_launcher"
label="
@string/app_name"
theme="
@style/AppTheme"
activity
com.example.v2_test.MainActivity"
intent-filter>
actionandroid:
android.intent.action.MAIN"
categoryandroid:
android.intent.category.LAUNCHER"
/intent-filter>
/activity>
meta-data
com.google.android.maps.v2.API_KEY"
value="
AIzaSyDmrnUUl_zWzgimKKeR5t3ZiinvouSWO8E"
/application>
/manifest>
布局文件
RelativeLayoutxmlns:
xmlns:
map="
layout_width="
match_parent"
layout_height="
fragment
id="
@+id/map"
class="
com.google.android.gms.maps.SupportMapFragment"
ImageButton
@+id/local"
background="
@null"
wrap_content"
layout_marginTop="
10dp"
layout_alignParentRight="
layout_marginRight="
/RelativeLayout>
菜单弹出框布局文件
TableLayoutxmlns:
fill_parent"
orientation="
vertical"
TextView
text="
起始位置:
textColor="
@android:
color/white"
textSize="
18dp"
/TextView>
EditText
@+id/start"
我的位置"
/EditText>
目的地:
@+id/end"
/TableLayout>
这个是activity
packagecom.example.v2_test;
importjava.io.BufferedReader;
importjava.io.IOException;
importjava.io.InputStream;
importjava.io.InputStreamReader;
importjava.util.ArrayList;
importjava.util.List;
importorg.apache.http.HttpEntity;
importorg.apache.http.HttpResponse;
importorg.apache.http.client.ClientProtocolException;
importorg.apache.http.client.HttpClient;
importorg.apache.http.client.methods.HttpGet;
importorg.apache.http.client.methods.HttpPost;
importorg.apache.http.impl.client.DefaultHttpClient;
importorg.json.JSONArray;
importorg.json.JSONException;
importorg.json.JSONObject;
importcom.google.android.gms.maps.CameraUpdateFactory;
importcom.google.android.gms.maps.GoogleMap;
importcom.google.android.gms.maps.SupportMapFragment;
importcom.google.android.gms.maps.model.CameraPosition;
importcom.google.android.gms.maps.model.LatLng;
importcom.google.android.gms.maps.model.Marker;
importcom.google.android.gms.maps.model.MarkerOptions;
importcom.google.android.gms.maps.model.Polyline;
importcom.google.android.gms.maps.model.PolylineOptions;
importandroid.app.AlertDialog;
importandroid.app.ProgressDialog;
importandroid.content.DialogInterface;
importandroid.content.DialogInterface.OnClickListener;
importandroid.graphics.Color;
importandroid.location.Criteria;
importandroid.location.Location;
importandroid.location.LocationListener;
importandroid.location.LocationManager;
importandroid.os.Bundle;
importandroid.os.Handler;
importandroid.os.Message;
importandroid.support.v4.app.FragmentActivity;
importandroid.util.Log;
importandroid.view.LayoutInflater;
importandroid.view.Menu;
importandroid.view.MenuItem;
importandroid.view.View;
importandroid.widget.EditText;
importandroid.widget.ImageButton;
publicclassMainActivityextendsFragmentActivity{
List<
LatLng>
list;
Polylinepolyline;
privateLocationlocation;
privateCameraPositioncameraPosition;
privateGoogleMapmap;
Stringstart="
Stringend="
doublelat=0.0;
doublelng=0.0;
doubleendlat=0.0;
doubleendlng=0.0;
LocationManagerlocationManager;
ImageButtonlocal;
LocationListenerllistener;
Markermarker;
privateProgressDialogprogressdialog;
privateHandlermHandler=newHandler(){
publicvoidhandleMessage(Messagemsg){
switch(msg.what){
case1:
progressdialog.dismiss();
if(polyline!
=null){
polyline.remove();
map.clear();
markMysition();
}
map.addMarker(newMarkerOptions().position(
newLatLng(endlat,endlng)).title(
MainActivity.this.getLocation(endlat,endlng)));
LatLnglast=null;
for(inti=0;
i<
list.size()-1;
i++){
LatLngsrc=list.get(i);
LatLngdest=list.get(i+1);
last=dest;
polyline=map.addPolyline(newPolylineOptions()
.add(newLatLng(src.latitude,src.longitude),
newLatLng(dest.latitude,dest.longitude))
.width(4).color(Color.GREEN));
}
break;
}
};
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
local=(ImageButton)findViewById(R.id.local);
local.setImageResource(R.drawable.ww);
//点击按钮视图回到我的位置
local.setOnClickListener(newandroid.view.View.OnClickListener(){
@Override
publicvoidonClick(Viewv){
MainActivity.this.setCameraPosition();
});
map=((SupportMapFragment)(this.getSupportFragmentManager()
this.getPointLocation();
MainActivity.this.setCameraPosition();
//标记我的位置
voidmarkMysition(){
marker=map.addMarker(newMarkerOptions().position(newLatLng(lat,lng)).title(
this.getLocation(lat,
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- googlemapapiv2 地图 导航