给用户的图形页面定义的注释 [英] give user defined annotation in mapview
本文介绍了给用户的图形页面定义的注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想探索在具有多个注释的图形页面我的城市,但我无法做到这一点。是任何一个建议我,我们怎么能与用户定义的经度和纬度的Android做到这一点。我创建了一个地图视图有一个注释但定义的系统,我必须从仿真器控制通过经度和纬度。我们如何发送与code与多个注释。
下面是我的code:
包com.ex.maps;进口的java.util.List;进口android.content.Context;
进口android.graphics.Bitmap;
进口android.graphics.BitmapFactory;
进口android.graphics.Canvas;
进口android.graphics.Paint;
进口android.graphics.Point;
进口android.location.Location;
进口android.location.LocationListener;
进口android.location.LocationManager;
进口android.os.Bundle;
进口android.util.Log;
进口android.view.ViewGroup;
进口android.view.ViewGroup.LayoutParams;
进口android.widget.Toast;
进口android.widget.ZoomControls;进口com.google.android.maps.GeoPoint;
进口com.google.android.maps.MapActivity;
进口com.google.android.maps.MapController;
进口com.google.android.maps.MapView;
进口com.google.android.maps.Overlay;公共类HelloGoogleMaps扩展MapActivity实现LocationListener的{
MapController MC;
GeoPoint的磷;
双纬度;
双LNG;
@覆盖
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
MapView的gMapView =(图形页面)findViewById(R.id.mapview);
gMapView.setBuiltInZoomControls(真);
GeoPoint的P =新的GeoPoint((INT)(LAT * 1000000),(INT)(LNG * 1000000));
gMapView.setSatellite(真);
MC = gMapView.getController();
mc.setCenter(P);
mc.setZoom(14);
LM的LocationManager =(的LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener的mlocListener =新HelloGoogleMaps();
//lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,mlocListener);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,1000L,500.0f,这一点);
ZoomControls zoomControls =(ZoomControls)gMapView.getZoomControls(); zoomControls.setLayoutParams(新ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); gMapView.addView(zoomControls); gMapView.displayZoomControls(真);
MyLocationOverlay myLocationOverlay =新MyLocationOverlay(); 清单<&叠加GT;清单= gMapView.getOverlays(); list.add(myLocationOverlay);
/ *列表与LT;叠加> mapOverlays = gMapView.getOverlays();
可绘制可绘制= this.getResources()getDrawable(R.drawable.arrow_icon)。
HelloItemizedOverlay itemizedoverlay =新HelloItemizedOverlay(绘制);
// GeoPoint的P =新的GeoPoint((INT)(LAT * 1000000),(INT)(LNG * 1000000));
OverlayItem overlayitem =新OverlayItem(点,霍拉,世界报!,我在墨西哥城!);
itemizedoverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedoverlay); * /
} 公共无效onLocationChanged(地点){
如果(位置!= NULL){
纬度= location.getLatitude();
LNG = location.getLongitude();
P =新的GeoPoint((INT)(LAT * 1000000),(INT)(LNG * 1000000));
mc.animateTo(P);
//Log.d(\"LOCATION化,location.getLatitude()+);
//Log.d(\"LOCATION化,location.getLongitude()+); * /
Toast.makeText(HelloGoogleMaps.this,
location.getLatitude()++ location.getLongitude(),
Toast.LENGTH_LONG).show();
}
}
// makeUseOfNewLocation(位置); 公共无效onProviderDisabled(字符串提供商){
}
公共无效onProviderEnabled(字符串提供商){
}
公共无效onStatusChanged(字符串提供商,INT地位,捆绑演员){
}
保护布尔isRouteDisplayed(){
返回true;
}
类MyLocationOverlay扩展com.google.android.maps.Overlay {
@覆盖 公共布尔平局(帆布帆布,MapView类MapView类,布尔阴影,长时){ super.draw(画布,MapView类,阴影);
涂料粉刷=新的油漆();
// LNG-Point转换为纬度/我们对屏幕上的坐标。
点myScreenCoords =新点();
MapView.getProjection()在toPixels(对,myScreenCoords)。
paint.setStrokeWidth(1);
paint.setARGB(255,255,255,255);
paint.setStyle(Paint.Style.STROKE);
BMP位图= BitmapFactory.de codeResource(getResources(),R.drawable.icon);
canvas.drawBitmap(BMP,myScreenCoords.x,myScreenCoords.y,油漆);
canvas.drawText(我在这里......,myScreenCoords.x,myScreenCoords.y,油漆);
返回true; }}
}
解决方案
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.favmapview);
listbtn =(按钮)findViewById(R.id.button1);
mapbtn =(按钮)findViewById(R.id.button2);
TextView的电视=(的TextView)findViewById(R.id.tvmap);
捆绑= getIntent()getExtras()。
STR1 = bundle.getString(钥匙);
纬度= bundle.getStringArrayList(纬度);
登录= bundle.getStringArrayList(日志);
位置= bundle.getStringArrayList(位置);
tv.setText(STR1);
listbtn.setOnClickListener(新View.OnClickListener(){ 公共无效的onClick(视图v){ // TODO自动生成方法存根
OpenListView(); //调用显示列表视图功能
}
});
initialiseMapView();
}
//导航到的ListView类和显示的ListView
保护无效OpenListView(){ 最后ProgressDialog对话框= ProgressDialog.show(FavMapView.this,HIV ATLAS 请稍候...,真正的);
最后的处理程序处理程序=新的处理程序(){ 公共无效的handleMessage(消息MSG){ dialog.dismiss();
}
}; 螺纹checkUpdate =新主题(){ 公共无效的run(){
意向意图=新意图(FavMapView.this,Favorites.class);
intent.putExtra(钥匙,bundle.getString(钥匙));
startActivity(意向);
dialog.dismiss();
handler.sendEmptyMessage(0); }
};
checkUpdate.start();
} // ============结束 @覆盖
公共布尔isRouteDisplayed(){
返回true;
}
//生成地图视图
私人无效initialiseMapView(){ 图形页面=(图形页面)findViewById(R.id.mapview);
mapController = mapView.getController();
mapView.setBuiltInZoomControls(真);
mapView.setSatellite(假); GeoPoint对象的startPoint =新的GeoPoint((INT)(40.7575 * 1E6),(INT)( - 73.9785 * 1E6));
mapController.setCenter(的startPoint); }
// ===============结束
@覆盖
公共无效调用onStart(){
super.onStart();
initialiseOverlays();
}
//设置查看地图地理点
私人无效initialiseOverlays(){
尝试{
//创建一个ItemizedOverlay显示标记列表
。可绘制defaultMarker = getResources()getDrawable(R.drawable.marker);
placesItemizedOverlay =新HelloItemizedOverlay(FavMapView.this,defaultMarker);
的for(int i = 0; I< log.size();我++)
{
双LAT1 = Double.parseDouble(lat.get(I));
双LOG1 = Double.parseDouble(log.get(I));
placesItemizedOverlay.addOverlayItem(新OverlayItem(新的GeoPoint((INT)(LAT1 * 1E6)
(中间体)(LOG1 * 1E6)),location.get(i)中,空));
}// ==============================结束
//将覆盖在地图上添加
调用MapView.getOverlays()加(placesItemizedOverlay)。
}赶上(NumberFormatException的E){
Toast.makeText(getApplicationContext(),无作业可用
Toast.LENGTH_SHORT).show();
// TODO自动生成catch块
e.printStackTrace();
}赶上(NotFoundException E){
Toast.makeText(getApplicationContext(),无作业可用
Toast.LENGTH_SHORT).show();
// TODO自动生成catch块
e.printStackTrace();
}
} }
I want to explore my cities on a mapview with multiple annotations but I unable to do that. Is any one suggest me that how can we do this in android with user defined longitude and latitude. I created a map view with one annotation but with system defined, I have to pass longitude and latitude from emulator control. how we send that with code with multiple annotation.
Here is my code:
package com.ex.maps;
import java.util.List;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.Toast;
import android.widget.ZoomControls;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
public class HelloGoogleMaps extends MapActivity implements LocationListener{
MapController mc;
GeoPoint p;
double lat;
double lng;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapView gMapView = (MapView) findViewById(R.id.mapview);
gMapView.setBuiltInZoomControls(true);
GeoPoint p = new GeoPoint((int) (lat * 1000000), (int) (lng * 1000000));
gMapView.setSatellite(true);
mc = gMapView.getController();
mc.setCenter(p);
mc.setZoom(14);
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener mlocListener = new HelloGoogleMaps();
//lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,mlocListener );
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L, 500.0f, this);
ZoomControls zoomControls = (ZoomControls) gMapView.getZoomControls();
zoomControls.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
gMapView.addView(zoomControls);
gMapView.displayZoomControls(true);
MyLocationOverlay myLocationOverlay = new MyLocationOverlay();
List<Overlay> list = gMapView.getOverlays();
list.add(myLocationOverlay);
/*List<Overlay> mapOverlays = gMapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.arrow_icon);
HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable);
//GeoPoint p = new GeoPoint((int) (lat * 1000000), (int) (lng * 1000000));
OverlayItem overlayitem = new OverlayItem(point, "Hola, Mundo!", "I'm in Mexico City!");
itemizedoverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedoverlay);*/
}
public void onLocationChanged(Location location) {
if (location != null) {
lat = location.getLatitude();
lng = location.getLongitude();
p = new GeoPoint((int) (lat * 1000000), (int) (lng * 1000000));
mc.animateTo(p);
//Log.d("LOCATION CHANGED", location.getLatitude() + "");
//Log.d("LOCATION CHANGED", location.getLongitude() + "");*/
Toast.makeText(HelloGoogleMaps.this,
location.getLatitude() + "" + location.getLongitude(),
Toast.LENGTH_LONG).show();
}
}
//makeUseOfNewLocation(location);
public void onProviderDisabled(String provider) {
}
public void onProviderEnabled(String provider) {
}
public void onStatusChanged(String provider, int status, Bundle extras) {
}
protected boolean isRouteDisplayed() {
return true;
}
class MyLocationOverlay extends com.google.android.maps.Overlay {
@Override
public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {
super.draw(canvas, mapView, shadow);
Paint paint = new Paint();
// Converts lat/lng-Point to OUR coordinates on the screen.
Point myScreenCoords = new Point();
mapView.getProjection().toPixels(p, myScreenCoords);
paint.setStrokeWidth(1);
paint.setARGB(255, 255, 255, 255);
paint.setStyle(Paint.Style.STROKE);
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
canvas.drawBitmap(bmp, myScreenCoords.x, myScreenCoords.y, paint);
canvas.drawText("Here I am...", myScreenCoords.x, myScreenCoords.y, paint);
return true;
} }
}
解决方案
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.favmapview);
listbtn = (Button)findViewById(R.id.button1);
mapbtn = (Button)findViewById(R.id.button2);
TextView tv = (TextView)findViewById(R.id.tvmap);
bundle = getIntent().getExtras();
str1= bundle.getString("key");
lat = bundle.getStringArrayList("lat");
log=bundle.getStringArrayList("log");
location = bundle.getStringArrayList("location");
tv.setText(str1);
listbtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
OpenListView(); // Function called to display list view
}
});
initialiseMapView();
}
// Navigates to listView class and displays listView
protected void OpenListView() {
final ProgressDialog dialog = ProgressDialog.show(FavMapView.this, "HIV ATLAS",
"Please wait...", true);
final Handler handler = new Handler() {
public void handleMessage(Message msg) {
dialog.dismiss();
}
};
Thread checkUpdate = new Thread() {
public void run() {
Intent intent = new Intent(FavMapView.this,Favorites.class);
intent.putExtra("key", bundle.getString("key"));
startActivity(intent);
dialog.dismiss();
handler.sendEmptyMessage(0);
}
};
checkUpdate.start();
}
//============End
@Override
public boolean isRouteDisplayed() {
return true;
}
//Generates Map View
private void initialiseMapView() {
mapView = (MapView) findViewById(R.id.mapview);
mapController = mapView.getController();
mapView.setBuiltInZoomControls(true);
mapView.setSatellite(false);
GeoPoint startPoint = new GeoPoint((int)(40.7575 * 1E6), (int)(-73.9785 * 1E6));
mapController.setCenter(startPoint);
}
//===============End
@Override
public void onStart() {
super.onStart();
initialiseOverlays();
}
// Sets Geo points on Map View
private void initialiseOverlays() {
try {
// Create an ItemizedOverlay to display a list of markers
Drawable defaultMarker = getResources().getDrawable(R.drawable.marker);
placesItemizedOverlay = new HelloItemizedOverlay (FavMapView.this, defaultMarker);
for(int i=0;i<log.size();i++)
{
double lat1 = Double.parseDouble(lat.get(i));
double log1 =Double.parseDouble(log.get(i));
placesItemizedOverlay.addOverlayItem(new OverlayItem(new GeoPoint((int)(lat1 * 1E6),
(int) (log1 * 1E6)),location.get(i),null));
}
//==============================End
// Add the overlays to the map
mapView.getOverlays().add(placesItemizedOverlay);
} catch (NumberFormatException e) {
Toast.makeText(getApplicationContext(), "No Jobs available",
Toast.LENGTH_SHORT).show();
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NotFoundException e) {
Toast.makeText(getApplicationContext(), "No Jobs available",
Toast.LENGTH_SHORT).show();
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
这篇关于给用户的图形页面定义的注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文