在我的所有其他项目中,我能够在任何MapView对象上调用getProjection()。这个项目由于某种原因是不同的...是因为即时通讯使用新的APIv2进行谷歌地图?任何想法?
package com.example.proximitystuff;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.Projection;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.maps.MapActivity;
import android.app.Activity;
import android.app.Fragment;
import android.graphics.Point;
import android.os.Bundle;
import android.view.MotionEvent;
public class MyMapActivity extends MapActivity {
private MapView map =null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_map);
MapView map = (MapView)findViewById(R.id.map);
//this line of code wont work... says projection cannot be resolved or is not a field
Projection projection= map.getProjection;
}
@Override
public boolean onTouchEvent(MotionEvent event){
int x = (int)event.getX();
int y = (int)event.getY();
Point p = new Point(x, y);
switch (event.getAction()){
case MotionEvent.ACTION_DOWN: //todo
case MotionEvent.ACTION_MOVE: //todo
case MotionEvent.ACTION_UP: //todo
}
return false;
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
答案 0 :(得分:3)
更改为:
GoogleMap googleMap = map.getMap();
Projection projection = googleMap.getProjection();
同时将MapActivity
替换为Activity
并删除isRouteDisplayed
。然后在此处开始阅读Google Maps Android API v2:https://developers.google.com/maps/documentation/android/start