google map 的使用

今天看了一些视频,学习的google map下面是一些总结
1生成密钥
步骤:首先获得密钥打开eclipse>window>preference>android>builde
然后打开cmd
进入下面的路劲

[img]http://dl.iteye.com/upload/attachment/0072/9069/95eb1bc9-0a03-3125-8279-fd2bb8ca6bdd.jpg[/img]
敲入
[img]http://dl.iteye.com/upload/attachment/0072/9072/c2bdd211-3e44-30aa-9f27-9d823139e5ff.jpg[/img]

获得md5码
[img]http://dl.iteye.com/upload/attachment/0072/9075/95921e8e-c767-368e-b515-63792c771c50.jpg[/img]
进入google网站注册,把你的md5码填进去
[url]https://developers.google.com/maps/documentation/android/maps-api-signup[/url]
生产的key用记事本记起来
在xml文件中,引入 <com.google.android.maps.MapView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="0oSMQIkVrCH2-x7f7MiHuQJUNXQ8H9m0pPUzQ6Q"
/>
在主activity extends MapActivity
在AndroidManifest.xml中加上<uses-permission android:name="android.permission.INTERNET"/>
在application节点下,加入 <uses-library android:name="com.google.android.maps"/>
下面的代码是实现地图的定位,街景,交通地图,卫星地图切换
package com.googlemap.activity;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends MapActivity {
private MapView mapview;
private MapController control;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapview=(MapView) this.findViewById(R.id.mapview);
control=mapview.getController();
mapview.setClickable(true);
mapview.setTraffic(true);
mapview.setBuiltInZoomControls(true);
control.setZoom(10);
mapview.setLongClickable(true);

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(1, 1, 1, "交通地图");
menu.add(2, 2, 2, "卫星地图");
menu.add(3,3,3,"街景模式");

return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case 1:
mapview.setTraffic(true);
mapview.setSatellite(false);
mapview.setStreetView(false);
break;
case 2:
mapview.setTraffic(false);
mapview.setSatellite(true);
mapview.setStreetView(false);
break;
case 3:
mapview.setTraffic(false);
mapview.setSatellite(false);
mapview.setStreetView(true);

default:
break;
}
return super.onOptionsItemSelected(item);
}

@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
public void UpdataMapshow(Double lat,Double lng){
int latI=(int) (lat*1E6);
int lngI=(int) (lng*1E6);

GeoPoint point=new GeoPoint(latI, lngI);
control.setCenter(point);
control.setZoom(mapview.getZoomLevel()-1);
control.animateTo(point);
}

}
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<com.google.android.maps.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="0oSMQIkVrCH2-x7f7MiHuQJUNXQ8H9m0pPUzQ6Q" />

</LinearLayout>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值