在地图上设置文字值点击Android

时间:2017-05-20 14:04:09

标签: android google-maps

  

块引用

我正在尝试使用此代码将“tap_text”值更改为点击坐标。我从githuub mapdemo复制了整个代码。 地图加载但“tap_text”在点击时永远不会改变。即使我手动尝试这一切也没有任何反应。我没有收到任何错误消息。

mTapTextView.setText("loaded");

整个代码:

package com.dji.amirdji;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMapClickListener;
import com.google.android.gms.maps.GoogleMap.OnMapLongClickListener;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

/**
 * This shows how to listen to some {@link GoogleMap} events.
 */
public class MapsActivity extends AppCompatActivity
        implements OnMapClickListener, OnMapLongClickListener,
        OnMapReadyCallback {

    private TextView mTapTextView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);

        mTapTextView = (TextView) findViewById(R.id.tap_text);

        SupportMapFragment mapFragment =
                (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
    }

    @Override
    public void onMapReady(GoogleMap map) {
        map.setOnMapClickListener(this);
        map.setOnMapLongClickListener(this);
    }

    @Override
    public void onMapClick(LatLng point) {
        mTapTextView.setText("tapped, point=" + point);
    }

    @Override
    public void onMapLongClick(LatLng point) {
        mTapTextView.setText("long pressed, point=" + point);
    }

}

我在清单中称呼它:

<activity
    android:name=".common.MapsActivity"
    android:label="Map" />

2 个答案:

答案 0 :(得分:0)

我调用了类而不是视图,它解决了问题。

mBtnMap.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        Intent intent = new Intent(getContext(), MapsActivity.class);
        getContext().startActivity(intent);
    }
});

答案 1 :(得分:0)

试试吧。

import createBrowserHistory from 'history/createBrowserHistory'
const history = createBrowserHistory()

history.listen((location, action) => {
  console.log(action, location.pathname, location.state)  //  <=== Never happens
})

render(
  <Provider store={store}>
    <Router history={history}>
      ...
    </Router>
  </Provider>,
  document.getElementById('root')
)