Seraph_浮生

导航

 
package seraph.map01;

import java.util.ResourceBundle.Control;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.Projection;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.UiSettings;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.maps.model.Polyline;
import com.google.android.gms.maps.model.PolylineOptions;
import com.google.android.maps.MapController;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
/**
 * Google Map V2 版本
 *  
 * @author Seraph
 *
 */
public class MainActivity extends FragmentActivity {
    private GoogleMap map =null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        //最低需要api11,得到GoogleMap对象
        map = ((SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map)).getMap();
        
        //添加地图标记,设置经纬度。设置点击标记显示的名称,信息,图片
        Marker marker= map.addMarker(new MarkerOptions()
        .position(new LatLng(30.523236, 111.990905))
        .title("嗨,你好!")
        .snippet("这是我的位置!"));
        //添加第二个标记
        map.addMarker(new MarkerOptions().position(new LatLng(30.523236, 113.990905))
                .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
        
        //得到一条细细的红线,Polyline代表折线。参数1:第一个坐标,参数2:第二个坐标,参数3:线的宽度,参数4:线的颜色
        map.addPolyline(new PolylineOptions()
         .add(new LatLng(30.523236, 111.990905), new LatLng(30.523236, 113.990905))
         .width(5)
         .color(Color.RED));
        
        //绘制一条折线
        PolylineOptions rectOptions = new PolylineOptions()
        .add(new LatLng(30.523236, 111.990905))
        .add(new LatLng(34.45, 122.0))
        .add(new LatLng(38.45, 125.2)) 
        .add(new LatLng(30.523236, 113.990905)).width(3)
         .color(Color.YELLOW);

        map.addPolyline(rectOptions);

        
        //Projection的作用是将屏幕上X轴和Y轴转换成地图上的经纬度
//        Projection projection = map.getProjection();
//        projection.fromScreenLocation(new Point(10, 10));
//        projection.toScreenLocation(new LatLng(30.523236, 118.990905));
    }
}

 

posted on 2013-04-06 18:33  Seraph_浮生  阅读(1067)  评论(0)    收藏  举报