Android开发--控制Google地图--添加缩放图标

/* (程序头部注释开始)
* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生
* All rights reserved.
* 文件名称:控制Google地图--添加缩放图标

* 作 者: 雷恒鑫
* 完成日期: 2012 年 08 月 12 日
* 版 本 号: V1.0
* 对任务及求解方法的描述部分
* 输入描述:
* 问题描述:
* 程序输出:

* 程序头部的注释结束

*/

打开“res/layout/main.xml”文件,修改后的程序

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<com.google.android.maps.MapView
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="0Thp5dGqLznn37TMAWzn6Dw4xdihZNa14lZWqiw"
android:clickable="true"
/>
<LinearLayout android="@+id/zoom"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    />
</RelativeLayout>


打开“src/com/demo/android/twstation/TrainStation.java”文件,修改后程序代码如下:

package com.demo.android.twstation;

import android.os.Bundle;
import android.view.ViewGroup;

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

public class TrainStation extends MapActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        findViews();
        setupMap();
    }
    private MapView map;
    private MapController mc;
    private ViewGroup zoom;
    
    private void findViews(){
    	map = (MapView) findViewById(R.id.map);
    	mc = map.getController();
    	
    	zoom = (ViewGroup) findViewById(R.id.zoom);
    	//zoom.addView(map.getZoomControls());
    }
    
    private void setupMap(){
    	GeoPoint station_taipei = new GeoPoint(
    			(int) (25.047192 * 1000000),
    			(int) (121.516981 * 1000000)
    			);
    	map.setTraffic(true);
    	map.setBuiltInZoomControls(true);
    	mc.setZoom(17);
    	mc.animateTo(station_taipei);
    }
    @Override
    protected boolean isRouteDisplayed(){
    	//TODO Auto-generated method stub
    	return false;
    }
}


运行结果:

 

放大后:

 

 

如果改成烟台大学的坐标,烟台大学就显示出来的,如下图所示:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

leihengxin

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值