我不能让这个工作.我尝试使用下面的代码与onTouchEventand,它不起作用.如果我在方法结束时返回true,我会得到带坐标的toast但不能移动地图,如果我返回false,我可以移动地图但是在用户点击地图后无法显示吐司.如果我做对了,另一个onTap方法仅用于单击叠加层.有没有人想到这个问题?
public boolean onTouchEvent(MotionEvent arg0, MapView arg1) {
//super.onTouchEvent(arg0);
int akcija = arg0.getAction();
if(akcija == MotionEvent.ACTION_UP){
if(!premik) {
Projection proj = mapView.getProjection();
GeoPoint loc = proj.fromPixels((int)arg0.getX(), (int)arg0.getY());
String sirina=Double.toString(loc.getLongitudeE6()/1000000);
String dolzina=Double.toString(loc.getLatitudeE6()/1000000);
Toast toast = Toast.makeText(getApplicationContext(), "Širina: "+sirina+" Dolzina: "+dolzina, Toast.LENGTH_LONG);
toast.show();
}
}
else if (akcija == MotionEvent.ACTION_DOWN){
premik= false;
}
else if (akcija== MotionEvent.ACTION_MOVE){
premik = true;
}
return false;
//return super.onTouchEvent(arg0);
}
Run Code Online (Sandbox Code Playgroud) 我的appn中有一个mapview.当页面加载时,我会在地图上显示一些点.我在该页面中也有一个搜索按钮.因此,在我提供搜索内容并单击搜索按钮后,地图不会刷新.只有当我们触摸地图上的任何地方时,它才会刷新.我也给了mapview.invalidate().还是行不通...
知道为什么会出现这个问题吗?
我试图在地图覆盖上放置一个标记,然后在用户选择drawable时显示一个对话框.问题是事件似乎重叠.单击地图并绘制标记后,onTap会立即触发,因为我刚刚绘制了标记,它直接位于onTap事件下,因此我的对话框始终会触发.有没有人对如何使这些事件互相排斥?
以下是地图活动的代码:
public class SelectGameLocation extends MapActivity implements GestureDetector.OnGestureListener, GestureDetector.OnDoubleTapListener {
private MapView mapView = null;
private SelectGameLocationItemizedOverlay selectLocationOverlay = null;
private List<Overlay> mapOverlays = null;
private GestureDetector gestureDetector = null;
@Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
//set the layout
setContentView(R.layout.activity_select_game_location);
//configure activity for double clicks
gestureDetector = new GestureDetector(this);
gestureDetector.setOnDoubleTapListener(this);
//create and configure mapview
mapView = (MapView) findViewById(R.id.selectGameLocation);
mapView.setBuiltInZoomControls(true);
mapView.setHapticFeedbackEnabled(true);
//configure the overlay to draw the icons on the map
mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.map_icon);
selectLocationOverlay …Run Code Online (Sandbox Code Playgroud) 我正在浏览Hello,MapView的文档,将MapView添加到我的Activity中.
当我启动我的Activity时,我在MapView上出现了通胀错误.
这是我的布局xml中的MapView:
<com.google.android.maps.MapView
android:id="@+id/mymap"
android:layout_width="fill_parent"
android:layout_height="200dip"
android:clickable="true"
android:apiKey="withheld"
/>
Run Code Online (Sandbox Code Playgroud)
这是我的MapActivity中的代码(该类名为ActivityDetails并扩展了MapActivity)类:
MapView mMap;
mMap = (MapView) findViewById(R.id.mymap);
mMap.setBuiltInZoomControls(true);
Run Code Online (Sandbox Code Playgroud)
这是错误:
06-10 09:15:24.277: ERROR/AndroidRuntime(228): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.my.app/com.my.app.activity.ActivityDetails}: android.view.InflateException: Binary XML file line #35: Error inflating class com.google.android.maps.MapView
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at android.os.Handler.dispatchMessage(Handler.java:99)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at android.os.Looper.loop(Looper.java:123)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at android.app.ActivityThread.main(ActivityThread.java:4363)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): …Run Code Online (Sandbox Code Playgroud) 我在MapView中收到一个我无法识别并且无法找到文档的错误.它看起来像这样:
CoreAnimation: ignoring exception:
Invalid Region <center:-180.00000000, -180.00000000
span:+2.81462803, +28.12500000>
Run Code Online (Sandbox Code Playgroud)
显然这些数字现在是我的代码所独有的,但我无法弄清楚发生了什么.MapView运行得很好,我的所有注释都会显示出来(它会像我设置的那样放大用户的位置).具体到底是什么意思?
谢谢.
这是我用来缩放到用户位置的方法.这有点不正统,但这是我得到帮助的原因,因为我出于各种原因遇到缩放问题(我可以解释,如果需要,但它可能不相关):
- (void)zoomToUserLocation:(MKUserLocation *)userlocation
{
if (!userlocation)
return;
MKCoordinateRegion region;
region.center = userlocation.coordinate;
region.span = MKCoordinateSpanMake(2.0, 2.0);
region = [self.mapView regionThatFits:region];
[self.mapView setRegion:region animated:YES];
}
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self zoomToUserLocation:self.mapView.userLocation];
}
- (void)mapView:(MKMapView *)theMapView didUpdateUserLocation:(MKUserLocation *)location
{
[self zoomToUserLocation:location];
}
Run Code Online (Sandbox Code Playgroud) 大家好我想在我的谷歌地图上实现叠加.但是我在运行时收到致命错误,似乎是某种NullPointerException.当我删除"overlayList = mapView.getOverlays();"时,应用程序正常运行 和"overlayList.add(t);" 代码行.任何帮助是极大的赞赏!
主要活动:
public class CSActivity extends MapActivity implements LocationListener {
MapController mapController;
MapView mapView;
LocationManager locationManager;
MyLocationOverlay myLocationOverlay;
MyLocationOverlay compass;
private Button click_but;
private Button exit_but;
long start;
long stop;
int x,y;
GeoPoint touchedPoint;
Drawable d;
List<Overlay> overlayList;
String towers;
int lat;
int lng;
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.main); // bind the layout to the activity
click_but = new Button(this);
click_but = (Button)findViewById(R.id.clickBtn);
exit_but = new Button(this);
exit_but = (Button)findViewById(R.id.exitBtn);
d = getResources().getDrawable(R.drawable.markerblue);
Touchy …Run Code Online (Sandbox Code Playgroud) android google-maps nullpointerexception fatal-error android-mapview
我正在使用谷歌地图,我的地图视图正在调试模式,我上次上传的应用程序工作正常,但当我用发布密钥和相同的密钥库导出它时,地图视图没有进一步显示,请帮助.我尝试过使用相同的密钥库和新的密钥库.我没有找到解决方案. 我已经提到我使用这些键我有钥匙.甚至是新的调试密钥库,来自keytool的调试密钥和来自谷歌控制台的Api
我正在尝试创建一个如何使用MapView.我创建了一个Fragment和一个XML来使用它.问题是当我尝试打开时,MapView会抛出一个 NullPointerException,但我无法理解为什么.
我该怎么解决?
XML
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.gms.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="160dp"
android:layout_marginRight="10dp" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
碎片
public class FormComoChegarEmpresa extends Fragment{
MapView mapView;
private GoogleMap googleMap;
private final String TAG = getClass().getSimpleName() + "->";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
((CustomDrawerLayout)getActivity()).getSupportActionBar().hide();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.como_chegar_empresa, container, false);
mapView = (MapView)view.findViewById(R.id.mapView);
return view;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setMapView();
}
private void setMapView() …Run Code Online (Sandbox Code Playgroud) 目前,我的swift应用程序具有一个带有各种注释的mapview,当用户从地图上的各种注释中走来时,总是不能向北锁定吗?我希望地图转向他们正在走的方向,而不是始终指向北。
这是我当前的updatelocation函数
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
{
let location = locations[0]
let myLocation:CLLocationCoordinate2D = CLLocationCoordinate2DMake(location.coordinate.latitude, location.coordinate.longitude)
let region:MKCoordinateRegion = MKCoordinateRegionMake(myLocation, noteTime.span)
map.setRegion(region, animated: true)
self.map.showsUserLocation = true
map.tintColor = UIColor(red:0.19, green:0.69, blue:0.73, alpha:1.0)
}
Run Code Online (Sandbox Code Playgroud)
我应该在这里声明吗?
android-mapview ×10
android ×8
google-maps ×3
xcode ×2
api ×1
fatal-error ×1
google-play ×1
ios ×1
overlay ×1
overlayitem ×1
rotation ×1
swift ×1
touch-event ×1