Android端 高德地圖點擊得到經緯度

來源:互聯網
上載者:User

標籤:override   sch   map   bottom   ntb   horizon   draw   cto   class   

<?xml version="1.0" encoding="utf-8"?><RelativeLayout    xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:id="@+id/activity_select_point"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:paddingBottom="@dimen/activity_vertical_margin"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin"    tools:context="com.example.euphemiaxiao.feedback.selectPoint">    <com.amap.api.maps.MapView        android:id="@+id/map"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:layout_above="@+id/doneSelect">    </com.amap.api.maps.MapView>    <Button        android:text="確認選點"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:id="@+id/doneSelect"        android:background="@android:color/holo_blue_light"        android:textSize="18sp"        android:layout_centerHorizontal="true"        android:layout_alignParentBottom="true"/></RelativeLayout>

 

package com.example.euphemiaxiao.feedback;import android.content.Intent;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.view.View;import android.widget.Button;import com.amap.api.maps.AMap;import com.amap.api.maps.CameraUpdateFactory;import com.amap.api.maps.MapView;import com.amap.api.maps.model.BitmapDescriptorFactory;import com.amap.api.maps.model.LatLng;import com.amap.api.maps.model.MarkerOptions;public class selectPoint extends AppCompatActivity implements AMap.OnMapClickListener{    private Button doneSelect;    private MapView mMapView = null;    private AMap aMap = null;    double latitude;    double longtitude;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_select_point);        //擷取地圖控制項引用        mMapView = (MapView) findViewById(R.id.map);        //在activity執行onCreate時執行mMapView.onCreate(savedInstanceState),建立地圖        mMapView.onCreate(savedInstanceState);        init();        doneSelect = (Button)findViewById(R.id.doneSelect);        doneSelect.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                Intent intent = new Intent(selectPoint.this,Feedback.class);                intent.putExtra("latitude",latitude);                intent.putExtra("longtitude",longtitude);                startActivity(intent);            }        });    }    private void init() {        if (aMap == null) {            aMap = mMapView.getMap();            setUpMap();        }    }    private void setUpMap() {        aMap.showIndoorMap(true);        LatLng latLng = new LatLng(39.92448, 116.518295);        aMap.moveCamera(CameraUpdateFactory.changeLatLng(latLng));//設定中心點        aMap.moveCamera(CameraUpdateFactory.zoomTo(18)); // 設定地圖可視縮放大小        aMap.setOnMapClickListener(this);    }    @Override    protected void onDestroy() {        super.onDestroy();        //在activity執行onDestroy時執行mMapView.onDestroy(),銷毀地圖        mMapView.onDestroy();    }    @Override    protected void onResume() {        super.onResume();        //在activity執行onResume時執行mMapView.onResume (),重新繪製載入地圖        mMapView.onResume();    }    @Override    protected void onPause() {        super.onPause();        //在activity執行onPause時執行mMapView.onPause (),暫停地圖的繪製        mMapView.onPause();    }    @Override    protected void onSaveInstanceState(Bundle outState) {        super.onSaveInstanceState(outState);        //在activity執行onSaveInstanceState時執行mMapView.onSaveInstanceState (outState),儲存地圖當前的狀態        mMapView.onSaveInstanceState(outState);    }    @Override    public void onMapClick(LatLng latLng) {        aMap.clear();        latitude=latLng.latitude;        longtitude=latLng.longitude;        MarkerOptions markerOptions = new MarkerOptions();        markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.placeholder));        markerOptions.position(latLng);        aMap.addMarker(markerOptions);        aMap.moveCamera(CameraUpdateFactory.changeLatLng(latLng));    }}

 

Android端 高德地圖點擊得到經緯度

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.