java importgeopoint_如何在地图上显示更多点(GeoPoint)?

目前,我能够在代码中显示第一个点(pointStatie)的一点,但我希望显示两个点。

我想要显示我所在的位置,以及我从另一个班级通过坐标的另一点。

我目前的代码是:

package aexp.elistcbox;

import android.os.Bundle;

import android.provider.SyncStateContract.Constants;

import com.google.android.maps.MapActivity;

import com.google.android.maps.MapView;

import com.google.android.maps.MapController;

import com.google.android.maps.GeoPoint;

import android.content.Context;

import android.content.Intent;

import android.content.res.Resources;

import android.location.Location;

import android.location.LocationListener;

import android.location.LocationManager;

import android.location.Criteria;

import android.util.Log;

import android.widget.Toast;

import android.location.Geocoder;

import android.location.Address;

import java.util.List;

import java.util.Locale;

import java.io.*;

import com.google.android.maps.Overlay;

import com.google.android.maps.OverlayItem;

import android.graphics.Canvas;

import android.graphics.Point;

import android.graphics.Bitmap;

import android.graphics.BitmapFactory;

import android.graphics.drawable.Drawable;

public class GPSLocatorActivity extends MapActivity

{

public MapView mapView;

public MapController mapController;

public LocationManager locationManager;

public LocationListener locationListener;

public String best;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.map_view);

mapView = (MapView) findViewById(R.id.mapView);

mapView.setSatellite(false);

mapView.setBuiltInZoomControls(true);

mapController = mapView.getController();

mapController.setZoom(13);

locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);

locationListener = new GPSLocationListener();

Bundle extras = getIntent().getExtras();

if(extras !=null)

{

double longitudine = extras.getDouble("long");

double latitudine = extras.getDouble("lat");

((GPSLocationListener) locationListener).setLongitudine(longitudine);

((GPSLocationListener) locationListener).setLatitudine(latitudine);

Log.e("longitudine", "* " + ((GPSLocationListener) locationListener).setLongitudine(longitudine));

Log.e("latitudine", "* " + ((GPSLocationListener) locationListener).setLatitudine(latitudine));

}

String provider = null;

if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {

provider = LocationManager.GPS_PROVIDER;

} else

if(locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {

provider = LocationManager.NETWORK_PROVIDER;

}

if(provider != null) {

locationManager.requestLocationUpdates(provider, 60000, 15, locationListener);

}

Criteria crit = new Criteria();

crit.setAccuracy(Criteria.ACCURACY_FINE);

best = locationManager.getBestProvider(crit, false);

locationManager.requestLocationUpdates(best, 60000, 15, locationListener);

Location loc = locationManager.getLastKnownLocation(provider);

locationListener.onLocationChanged(loc);

}

@Override

protected boolean isRouteDisplayed() {

return false;

}

@Override

protected void onResume() {

super.onResume();

//locationManager.requestLocationUpdates(best, 10000, 1, locationListener);

Toast.makeText(this, "GPS tracking started",

Toast.LENGTH_SHORT).show();

// Start location updates; 5s/5m

LocationManager locManager = (LocationManager)getSystemService(

Context.LOCATION_SERVICE);

locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,

60000, 15, locationListener);

Criteria crit = new Criteria();

crit.setAccuracy(Criteria.ACCURACY_FINE);

String provider = locManager.getBestProvider(crit, true);

Location loc = locManager.getLastKnownLocation(provider);

}

@Override

protected void onPause() {

super.onPause();

//locationManager.removeUpdates(locationListener);

Toast.makeText(this, "GPS tracking stopped",

Toast.LENGTH_SHORT).show();

LocationManager locManager = (LocationManager)getSystemService(

Context.LOCATION_SERVICE);

locManager.removeUpdates(locationListener);

}

private class GPSLocationListener implements LocationListener

{

double longitudine;

double latitudine;

public double setLongitudine(double longitudine) {

return this.longitudine = longitudine;

}

public double setLatitudine(double latitudine) {

return this.latitudine = latitudine ;

}

public void onLocationChanged(Location location) {

Toast.makeText(GPSLocatorActivity.this, "Te plimbi",

Toast.LENGTH_SHORT).show();

if (location != null) {

Log.e("longitudine", "*2 " + longitudine);

Log.e("latitudine", "*2 " + latitudine);

GeoPoint pointStatie = new GeoPoint(

(int) (latitudine * 1E6),

(int) (longitudine * 1E6));

GeoPoint point = new GeoPoint(

(int) (location.getLatitude() * 1E6),

(int) (location.getLongitude() * 1E6));

// afisaza coordonatele

/*

Toast.makeText(getBaseContext(),

"Latitude: " + location.getLatitude() +

" Longitude: " + location.getLongitude(),

Toast.LENGTH_SHORT).show();

*/

mapController.animateTo(point);

mapController.animateTo(pointStatie);

mapController.setZoom(13);

//mapView.invalidate();

// add marker for people point

MapOverlay mapOverlay = new MapOverlay();

mapOverlay.setPointToDraw(point);

mapOverlay.setPointToDraw(pointStatie);

List listOfOverlays = mapView.getOverlays();

listOfOverlays.clear();

listOfOverlays.add(mapOverlay);

String address = ConvertPointToLocation(point);

Toast.makeText(getBaseContext(), address, Toast.LENGTH_SHORT).show();

String addressStatie = ConvertPointToLocation(pointStatie);

Toast.makeText(getBaseContext(), addressStatie, Toast.LENGTH_SHORT).show();

}

}

public String ConvertPointToLocation(GeoPoint point) {

String address = "";

Geocoder geoCoder = new Geocoder(

getBaseContext(), Locale.getDefault());

try {

List

addresses = geoCoder.getFromLocation(

point.getLatitudeE6() / 1E6,

point.getLongitudeE6() / 1E6, 1);

if (addresses.size() > 0) {

for (int index = 0;

index < addresses.get(0).getMaxAddressLineIndex(); index++)

address += addresses.get(0).getAddressLine(index) + " ";

}

}

catch (IOException e) {

e.printStackTrace();

}

return address;

}

class MapOverlay extends Overlay

{

private GeoPoint pointToDraw;

public void setPointToDraw(GeoPoint point) {

pointToDraw = point;

}

public GeoPoint getPointToDraw() {

return pointToDraw;

}

@Override

public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {

super.draw(canvas, mapView, shadow);

// convert point to pixels

Point screenPts = new Point();

mapView.getProjection().toPixels(pointToDraw, screenPts);

// add marker

Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.mark_red);

canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null);

return true;

}

}

public void onProviderDisabled(String provider) {

}

public void onProviderEnabled (String provider) {

}

public void onStatusChanged(String provider, int status, Bundle extras) {

}

}

}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/459780.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Java实现串口通信的小样例

用Java实现串口通信&#xff08;windows系统下&#xff09;&#xff0c;须要用到sun提供的串口包 javacomm20-win32.zip。当中要用到三个文件&#xff0c;配置例如以下&#xff1a; 1.comm.jar放置到 JAVA_HOME/jre/lib/ext; 2.win32com.dll放置到 JAVA_HOME/bin; 3.javax.comm…

庆祝教师节,李宁老师课程优惠劵疯抢中、会员卡优惠中,先到先得

李宁老师会员卡&#xff08;9-10至9-14&#xff09;大优惠&#xff1a;http://edu.51cto.com/member/id-12_1.html优惠劵只能购买李宁老师的视频课程&#xff1a;http://edu.51cto.com/member/id-12_1.html 优惠劵有效期&#xff1a;2015-9-10 至 2015-9-14 购买规则&#xf…

java mset_Java 反射机制(包括组成、结构、示例说明等内容)

第1部分 Java 反射机制介绍Java 反射机制。通俗来讲呢&#xff0c;就是在运行状态中&#xff0c;我们可以根据“类的部分已经的信息”来还原“类的全部的信息”。这里“类的部分已经的信息”&#xff0c;可以是“类名”或“类的对象”等信息。“类的全部信息”就是指“类的属性…

XML序列化和反序列化 以及相关类的写法

类的写法&#xff1a; 省网办数据对接中运用到 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml.Serialization;namespace SWBExchange.Common.Entities {public class Body{[XmlElement(ElementName "BasicIn…

python-main

当你打开一个.py文件时,经常会在代码的最下面看到if __name__ __main__:,现在就来介 绍一下它的作用.模块是对象&#xff0c;并且所有的模块都有一个内置属性 __name__。一个模块的 __name__ 的值取决于您如何应用模块。如果 import 一个模块&#xff0c;那么模块__name__ 的值…

自己动手,实现一种类似ListT的数据结构(二)

前言&#xff1a; 首先&#xff0c;小匹夫要祝各位看官圣诞快乐&#xff0c;新年愉快&#xff5e;。上一篇文章《自己动手&#xff0c;实现一种类似List<T>的数据结构(一&#xff09;》 介绍了一下不依靠List<T>实现的各种接口&#xff0c;仿造一个轻量级数据结构的…

java spring jdbc_Spring与JDBC支持

JDBC是一种标准Java编程接口(JAVA API)&#xff0c;可以将Java编程语言与广泛数据库进行连接。JDBC API库包含下面提到的每个任务&#xff0c;都是与数据库相关的常用用法。数据库的连接创建sql语句执行或提交sql语句查看或修改查询到的记录从根本上说&#xff0c;JDBC是一种规…

局域网内连接MySQL

2019独角兽企业重金招聘Python工程师标准>>> 局域网内连接MySQL 博客分类&#xff1a; MySQL MySQL局域网连接grant 我们都知道连接MySQL一般用的语句就是 jdbc:mysql://localhost:3306/database&#xff0c; 但是当你要连接到其他机器上的mysql的时候&#xff0c;…

java打印的globa类l_Spring异常集中处理和日志集中打印

使用ControllerAdvice和ExceptionHandler处理Controller层的异常&#xff1a;ControllerAdvicepublic class GlobalExceptionHandler {private static final Logger LOGGER LoggerFactory.getLogger(GlobalExceptionHandler.class);/*** 处理所有不可知的异常* param e* retur…

[leetcod] Clone Graph

题目&#xff1a; Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. OJs undirected graph serialization: Nodes are labeled uniquely. We use # as a separator for each node, and , as a separator for node label and …

【iOS7一些总结】9、与列表显示(在):列表显示UITableView

列表显示&#xff0c;顾名思义它是在一个列表视图的形式显示在屏幕上的数据的内容。于ios在列表视图UITableView达到。这个类在实际应用中频繁&#xff0c;是很easy理解。这里将UITableView的主要使用方法总结一下以备查。UITableView定义在头文件UITableView.h中&#xff0c;详…

java聊天软件课程设计_[计算机课程设计] JAVA课程设计-聊天室

本系统基于C/S模式。新的时代,新的世纪,在当今这个发达的信息时代,网上办公,极为普遍,生活变的简单化,人们在家就可以办公,是信息化时代的标志.我经过多方的调查和研究,并灵活运用了自己所学的知识,编写了这个非常适用的一个小软件.它是通过RMI通信协议,利用JAVA的多线程技术,将…

iOS 获取手机信息

待续&#xff1b;转载于:https://www.cnblogs.com/xieyier/p/4194271.html

show status和show variables区别解析

1.show status 查看系统运行的实时状态&#xff0c;便于dba查看mysql当前运行的状态&#xff0c;做出相应优化&#xff0c;动态的&#xff0c;不可认为修改&#xff0c;只能系统自动update。MariaDB [(none)]> show status like %conn%;--------------------------------…

【Javascript 拾遗之三】Closure 闭包

说起闭包这个概念&#xff0c;其实是离散数学中的一种定义&#xff0c;而很程序员们耳熟能详但不一定能说清楚它的含义和用途。本文先简单地介绍下离散数学中的闭包&#xff0c;然后再探讨一下Javascript语言中的闭包是如何创建和应用的。 Closure 闭包 1、闭包的定义 -离散数学…

java递归空瓶换饮料_问题描述:一次买n瓶可乐,k个空瓶可以换一瓶饮料,那么一共能喝多少瓶饮料? | 学步园...

/***问题描述&#xff1a;一次买n瓶可乐&#xff0c;k个空瓶可以换一瓶饮料&#xff0c;那么一共能喝多少瓶饮料&#xff1f;*下面用不同的方法实现了这个问题(Java实现)&#xff1a;*1.递归方法*2.非递归方法*3.公式法*/public class CocaCola{public int Count(int n, int k)…

SpringMVC(一):环境搭建

2019独角兽企业重金招聘Python工程师标准>>> //TODO 转载于:https://my.oschina.net/u/1020238/blog/505272

DockPanel 类

DockPanel 类 .NET Framework 4.5其他版本此主题尚未评级 - 评价此主题定义您可水平或垂直排列子元素的区域&#xff0c;互相。 继承层次结构 System.Object System.Windows.Threading.DispatcherObjectSystem.Windows.DependencyObjectSystem.Windows.Media.VisualSystem.Wind…

java动态json入库_从JSon File动态生成模式

一些兴趣点&#xff1a;1)您不需要数据帧来加载您的json架构 . 模式在驱动程序上加载和执行&#xff0c;因为不需要分发那些不必要的开销2)我构造了一个JColumn对象的List&#xff0c;并将它传递给StructType以动态构造模式3)inferSchema应该是false&#xff0c;因为我们明确定…

【分布式计算】MapReduce的替代者-Parameter Server

原文&#xff1a;http://blog.csdn.net/buptgshengod/article/details/46819051 首先还是要声明一下&#xff0c;这个文章是我在入职阿里云1个月以来&#xff0c;对于分布式计算的一点肤浅的认识&#xff0c;可能有些地方不够妥善&#xff0c;还请看官可以指出不足的地方&#…