Tag: 位置

谷歌地图v2 – 绘制不同颜色的路线 – Android

我正在构建一个基于位置的Android应用程序,我想根据他的速度绘制用户需要的路线。 例如:0-10kmh – 黄色折线10-20kmh – 红色折线 现在我在后台服务中运行所有内容并更新Map Activity; 定位服务 : if (location.getSpeed() >0 && location.getSpeed 10 && location.getSpeed < 20) { redPolyLineArray.add(new LatLng(location.getLatitude(), location.getLongitude())); polylineIntent.putParcelableArrayListExtra("red",redPolyLineArray); } 这一切都是在onLocationChanged方法中完成的,每次用户移动时,我都会使用本地广播接收器发送数组列表来映射活动: private BroadcastReceiver mDrawRouteRec = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { //Receiver array of yellowspeed polylines yellowPolyline = intent.getParcelableArrayListExtra(“yellow”); if(yellowPolyline != null){ //Implement polyline […]

Android通过位置管理器获取经度和纬度

我正在尝试使用位置管理器获取用户位置,但该位置始终返回null。 我也要求用户打开gps。 这是我的代码: int permisioncheck = ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION); if(permisioncheck == 0){ lm = (LocationManager)getContext().getSystemService(Context.LOCATION_SERVICE); List providers = lm.getProviders(true); Location bestLocation = null; for (String provider : providers) { Location location = lm.getLastKnownLocation(provider); if (location == null) { continue; } if (bestLocation == null || location.getAccuracy() < bestLocation.getAccuracy()) { // Found best last known location: %s", […]

Android:getfromLocationName()在地址列表中返回大小0

我有一个位置数据库。 当我尝试将它们转换为坐标时,我可以将它们放在地图上,我会收到错误。 我的地址类型地址列表的大小为零。 我研究了这个话题。 我的所有清单权限都是正确的。 我的手机已连接到互联网。 我重新启动了手机。 我知道有一个谷歌问题,解决方案没有帮助。 位置准确。 请帮忙。 这是错误消息:android.database.CursorIndexOutOfBoundsException:请求索引0,大小为0 private void setUpMap() { DatabaseHandler db = new DatabaseHandler(this); Cursor c = db.fetchAllAddresses(); String place = c.getString(c.getColumnIndex(“name”)); Geocoder geocoder = new Geocoder(this, Locale.getDefault()); List addresses = new ArrayList(); try { addresses = geocoder.getFromLocationName(place,1); } catch (IOException e) { e.printStackTrace(); } android.location.Address add = addresses.get(0); […]

难以将用户1的位置发送给用户2,将用户2的位置发送给用户1?

我有一个代码将用户1的位置发送给用户2,用户2的位置发送给用户1。 用户1的位置完美地发送给用户2,用户2甚至向用户1发送消息,但是它发送的位置是用户1的位置而不是他(用户2)的位置。 这是我的代码: package com.example.gui; import android.app.Activity; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.ContentResolver; import android.content.ContentValues; import android.content.Context; import android.content.Intent; import android.database.Cursor; import android.location.Geocoder; import android.location.Location; import android.location.LocationManager; import android.net.Uri; import android.os.Bundle; import android.telephony.SmsManager; import android.telephony.SmsMessage; import android.util.Log; import android.view.View; import android.widget.Toast; public class ReceivelocationActivity extends BroadcastReceiver { private static final String TAG = “LocationActivity”; public […]

模拟GPS位置问题

我正在开发一个获取用户指定的纬度,经度和海拔高度的APP,然后在手机上伪造这个GPS位置,并显示我在谷歌地图中的那个位置。 我对清单文件具有所需权限,并且在开发人员设置中启用了模拟位置。 LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); //lm.clearTestProviderEnabled(mocLocationProvider); lm.addTestProvider(mocLocationProvider, false, false, false, false, false, false, false, 0, 10); lm.setTestProviderEnabled(mocLocationProvider, true); mockLocation = new Location(mocLocationProvider); // a string mockLocation.setLatitude(Integer.parseInt(latitude.getText().toString())); // double mockLocation.setLongitude(Integer.parseInt(longitude.getText().toString())); mockLocation.setAltitude(Integer.parseInt(altitude.getText().toString())); mockLocation.setTime(System.currentTimeMillis()); lm.setTestProviderLocation( mocLocationProvider, mockLocation); 但看起来我的GPS位置在谷歌地图上根本没有改变,有什么问题? 更新:我刚刚在我的手机上安装了一个名为“伪GPS位置”的应用程序,该应用程序工作正常,但我仍然不知道我的代码有什么问题,但我认为我的正式方法是实现这一点。 更新#2:虽然一些类似的应用程序可以在我的手机上运行,​​但我发现了一些例外, http://www.cowlumbus.nl/forum/MockGpsProvider.zip ,这个应用程序无法在我的手机上运行。 有人可以帮我解决这个问题吗? 数百万的谢谢! 每次设置位置时我都没有收到任何错误消息。 更新#3:我注意到这个应用程序相当陈旧,所以它不能在4.1上运行。 如果是这样,如何在新版本中做同样的事情? 我的手机是三星galaxy s3,希望它有所帮助。 更新#4:对于您的信息,我的更新#2中的应用程序代码是: package nl.cowlumbus.android.mockgps; import java.io.BufferedReader; import java.io.InputStream; […]

对java属性文件位置感到困惑

我有简单的java项目结构: package com.abc: a.java b.java c.properties 我在c.properties文件中配置了数据库配置参数。 在a.java和b.java中,我使用以下命令加载属性文件: Properties p = new Properties(); InputStream in = this.getClass().getResourceAsStream(“c.properties”); p.load(in); 这很好用。 但主要问题是,一旦我通过导出此代码准备可执行jar,属性文件也会打包在jar文件中。 如果其他人想要修改不同数据库配置的属性文件,他怎么能这样做? 我是否必须将属性文件存储在本地计算机的某个固定位置。 例如“c:/”。 然后将jar和属性文件一起提供给另一个人。 然后他需要复制C:/ location中的属性文件? 还有一个问题,我如何使这个位置通用的Windows和Linux机器?

位置每35秒更新一次,并在当前位置绘制一个圆圈

目前,我每隔35秒改变位置并移动10米距离,就在我的Current Location绘制一个Circle 。 因此,一旦位置发生变化(移动35秒和10米),我就在LocationChanged下实现了此function,我Circle on the Google Maps on the Current Location绘制了一个Circle on the Google Maps on the Current Location 。 问题陈述:- My App is running very slow 。 有时我的应用程序被绞死了? 可能是因为我的代码不像我在下面写的那样有效吗? 基本上,我只需要在每35秒移动10米的距离后在当前位置画一个圆圈。 我的代码有问题吗? 任何想法,比如我应该如何改进这一点,顺利运行它。 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationListener = new GPSLocationListener(); locationManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 35000, 10, locationListener); […]

Trilateration方法Android Java

我有一点问题……有谁知道我该如何实现这个? 我需要一个像java这样的方法: public /*COORDINATE OBJECT*/ getTrilaterationPointBetween( /*COORDINATE OBJECT*/ coordinate1, double distance1, /*COORDINATE OBJECT*/ coordinate2, double distance2, /*COORDINATE OBJECT*/ coordinate3, double distance3){ //MAGIC return /*COORDINATE OBJECT*/; } 在实践中,这个方法将接收3个坐标和“myLocation”与其中一个之间的距离…… 我需要Trilateration的算法!! 我做了一些搜索并做了一些测试,结果让我进入了太平洋的中间! 关于OBJECT,非常简单,有两个代表纬度和经度的变量。 我试过这个方法: static double[] MyTrilateration(Ponto ponto1, double dist1, Ponto ponto2, double dist2, Ponto ponto3, double dist3) { double[] tmpWAP1 = new double[3]; double[] tmpWAP2 = new […]

JPanel setLocation

其中说:usePanel.setLocation(800,usePanel.getY()); 它没有设置它刚刚在中间开始的位置,但是在for循环中,它逐渐改变了一个很酷的动画的位置,它工作正常。 知道为什么第一个设置位置开始工作不起作用? 这是在FlowLayout btw下,所以我认为可能与它有关但不确定。 usePanel.setLocation(800,usePanel.getY()); for(int x=0;x<3500;x+=6){ usePanel.setLocation(usePanel.getX()-5,usePanel.getY()); Thread.sleep(500); } 更新了当前代码 private Timer nextloc; private JPanel usePanel; private static ClosePanel cp = new ClosePanel(“null”); public void run(){ Timer andgo = new Timer(10,new TimerListener()); while(!cp.getCloseDone()){ andgo.start(); andgo.restart(); } if(panel.equals(“topiccreator”)){ usePanel=topiccreator; }else{ System.out.println(“NULL PANEL TO MOVE!”); usePanel=mainmenu; } //This is what is not working usePanel.setLocation(usePanel.getX()+800,usePanel.getY()); usePanel.setVisible(true); […]

翻转旋转和图像

我正在编写一个Java平台游戏,我正在手动编写播放器动画。 我分别为每个肢体制作动画,改变位置和旋转。 当玩家面向右侧时,此function正常,但当玩家面向左侧时,我不知道如何处理旋转以使玩家向左转时看起来相同。 每个身体部位的位置都是相对于玩家的x和y值存储的,所以我真的需要一种方法来水平翻转旋转。 我知道我并没有很好地解释这一点,但如果有人理解我想说的并且可以提供帮助,我会非常感激。 先谢谢你。 🙂