展会信息港展会大全

googl Map入门用法的简单实例 android开发教程
来源:互联网   发布日期:2015-09-24 20:32:38   浏览:2096次  

导读:Android开发要连接GoogelMaps使用MapView时需要,先从Google网站申请一组经过验证的Maps API Key授权码,这个在网上很多1.[图片] 未命名.jpg2.[代码][Java]代码package com.android.antking.map;import com......

Android开发要连接GoogelMaps使用MapView时需要,先从Google网站申请一组经过验证的Maps API Key授权码,这个在网上很多

1. [图片] 未命名.jpg

2. [代码][Java]代码

package com.android.antking.map;

import com.google.android.maps.MapActivity;

import com.google.android.maps.GeoPoint;

import com.google.android.maps.MapController;

import com.google.android.maps.MapView;

import android.os.Bundle;

public class MyMain extends MapActivity {

//放大倍数

static final int INITIAL_ZOOM_LEVEL=12;

//中心点

static final int INITIAL_LATITUDE=123465465;

static final int INITIAL_LONGITUDR=15634646;

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

MapView mapView = (MapView) findViewById(R.id.mapView);

//enable to change the size of the map

mapView.setBuiltInZoomControls(true);

//设置Zoom 大小和地图的中心点

MapController mc = mapView.getController();

mc.setZoom(INITIAL_ZOOM_LEVEL);

mc.setCenter(new GeoPoint(INITIAL_LATITUDE,INITIAL_LONGITUDR));

}

@Override

protected boolean isRouteDisplayed() {

// TODO Auto-generated method stub

return false;

}

}

3. [代码][XML]代码

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

<TextView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/hello"

/>

<com.google.android.maps.MapView

android:id="@+id/mapView"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:enabled="true"

android:clickable="true"

android:apiKey="0FZLYf-YM4SRrJrJum55MeeaO4Gd_IitVFmtUeA"/>这个是自己开发的google mapApi 密钥

</LinearLayout>

4. [代码]在这里加上google的地图包,还有Internet权限

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.android.antking.map"

android:versionCode="1"

android:versionName="1.0">

<uses-sdk android:minSdkVersion="7" />

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

<application android:icon="@drawable/icon" android:label="@string/app_name">

<activity android:name=".MyMain"

android:label="@string/app_name">

<intent-filter>

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

<uses-library android:name="com.google.android.maps"></uses-library>

</application>

</manifest>

赞助本站

人工智能实验室

相关热词: googl Map 实例

相关内容
AiLab云推荐
推荐内容
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港