- 浏览: 207518 次
- 性别:
- 来自: 大连
文章分类
- 全部博客 (54)
- java (17)
- hibernate (3)
- javascript (6)
- Ajax (1)
- 插件 (2)
- 数据库 (3)
- html+css+div (5)
- 其他程序 (3)
- 应用技术 (18)
- office (0)
- 小工具 (1)
- 加密解密 (3)
- mac (3)
- 翻译 (1)
- iphone objectc (5)
- iphone (4)
- android (12)
- 圆角 (1)
- layout (2)
- 加密 (1)
- proguard (2)
- Mac 应用技术 系统 工具 (2)
- Mac 应用技术 系统 工具,xcode4 (1)
- 安卓 (6)
- maven (3)
- 高德 (1)
- 地图 (1)
- lrzsz (1)
- rz (1)
- sz (1)
- 脚本 (1)
- linux (1)
- Android Gradle (1)
- Spark (1)
- mongodb (1)
最新评论
-
Jumper_Wu:
想请教个问题:so文件从maven库中拉到AndroidStu ...
在maven android 工程中使用高德地图 -
cuiqi4016:
可不可以把把html模版作为一个单独的文件引入进来,handl ...
Handlebars 的使用 -
lywangbadan:
Handlebars 的使用 -
lituo20:
不错的,以前接触过一点,看了一下,恍然大悟,好像一下子懂了
Handlebars 的使用 -
zhangyaochun:
其实就是模板化,这是以前就开始推崇的面向数据编程的一个方式。比 ...
Handlebars 的使用
This example show you how to draw movable marker on to map. You can darg and drop the marker to change its position. Can be used in any application where u want to take input from user for map location.
Algorithm:
1.) Create a new project by File-> New -> Android Project name it MapMarkerExample.
2.) You will see some default code into your main.xml and android manifest file.
3.) Add internet permission to your manifest file or write following in android.manifest file:
4.) Write following into main.xml file:
5.) CreateYour own map API key and replace it in above main.xml.
6.) Add any marker image or push pin image in drawable folder.
7.) Run for output.
Steps:
1.) Create a project named MapMarkerExample and set the information as stated in the image.
Build Target: Android 2.1 (Google API)
Application Name: MapMarkerExample
Package Name: com.example.mapmarker
Activity Name: MapMarkerActivity
Min SDK Version: 7
2.) Open MapMarkerActivity.java file and write following code there:
3.) Compile and build the project.
4.) Move the marker shown on the map with the help of mouse for results shown below.
Output
Algorithm:
1.) Create a new project by File-> New -> Android Project name it MapMarkerExample.
2.) You will see some default code into your main.xml and android manifest file.
3.) Add internet permission to your manifest file or write following in android.manifest file:
<?xml version="1.0" encoding="utf-8"?> <manifest package="com.example.mapmarker" xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="7" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <application android:icon="@drawable/icon" android:label="@string/app_name"> <uses-library android:name="com.google.android.maps" /> <activity android:label="@string/app_name" android:name=".MapMarkerActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
4.) Write following into main.xml file:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"> <com.google.android.maps.MapView android:id="@+id/map" android:layout_width="wrap_content" android:layout_height="wrap_content" android:apiKey="0jp8vWjNayJISFKdvcJwGmwsjgoCoQrT_dflCfQ" android:clickable="true" /> <ImageView android:id="@+id/drag" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/marker" android:visibility="gone" /> </RelativeLayout>
5.) CreateYour own map API key and replace it in above main.xml.
6.) Add any marker image or push pin image in drawable folder.
7.) Run for output.
Steps:
1.) Create a project named MapMarkerExample and set the information as stated in the image.
Build Target: Android 2.1 (Google API)
Application Name: MapMarkerExample
Package Name: com.example.mapmarker
Activity Name: MapMarkerActivity
Min SDK Version: 7
2.) Open MapMarkerActivity.java file and write following code there:
package com.example.mapmarker; import java.util.ArrayList; import java.util.List; import android.graphics.Canvas; import android.graphics.Point; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; import android.widget.ImageView; import android.widget.RelativeLayout; import android.widget.Toast; import com.google.android.maps.GeoPoint; import com.google.android.maps.ItemizedOverlay; import com.google.android.maps.MapActivity; import com.google.android.maps.MapView; import com.google.android.maps.MyLocationOverlay; import com.google.android.maps.OverlayItem; public class MapMarkerActivity extends MapActivity { private MapView map=null; private MyLocationOverlay me=null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); map=(MapView)findViewById(R.id.map); map.getController().setCenter(getPoint(21.0000169992044, 78.0000484771729)); map.setBuiltInZoomControls(true); Drawable marker=getResources().getDrawable(R.drawable.marker); marker.setBounds(0, 0, marker.getIntrinsicWidth(),marker.getIntrinsicHeight()); map.getOverlays().add(new SitesOverlay(marker)); me=new MyLocationOverlay(this, map); map.getOverlays().add(me); } @Override public void onResume() { super.onResume(); me.enableCompass(); } @Override public void onPause() { super.onPause(); me.disableCompass(); } @Override protected boolean isRouteDisplayed() { return(false); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_S) { map.setSatellite(!map.isSatellite()); return(true); } else if (keyCode == KeyEvent.KEYCODE_Z) { map.displayZoomControls(true); return(true); } return(super.onKeyDown(keyCode, event)); } private GeoPoint getPoint(double lat, double lon) { return(new GeoPoint((int)(lat*1000000.0), (int)(lon*1000000.0))); } private class SitesOverlay extends ItemizedOverlay<OverlayItem> { private List<OverlayItem> items=new ArrayList<OverlayItem>(); private Drawable marker=null; private OverlayItem inDrag=null; private ImageView dragImage=null; private int xDragImageOffset=0; private int yDragImageOffset=0; private int xDragTouchOffset=0; private int yDragTouchOffset=0; public SitesOverlay(Drawable marker) { super(marker); this.marker=marker; dragImage=(ImageView)findViewById(R.id.drag); xDragImageOffset=dragImage.getDrawable().getIntrinsicWidth()/2; yDragImageOffset=dragImage.getDrawable().getIntrinsicHeight(); items.add(new OverlayItem(getPoint(21.169992044, 78.484771729), "Mumbai", "Maharashtra, India")); populate(); } @Override protected OverlayItem createItem(int i) { return(items.get(i)); } @Override public void draw(Canvas canvas, MapView mapView, boolean shadow) { super.draw(canvas, mapView, shadow); boundCenterBottom(marker); } @Override public int size() { return(items.size()); } @Override public boolean onTouchEvent(MotionEvent event, MapView mapView) { final int action=event.getAction(); final int x=(int)event.getX(); final int y=(int)event.getY(); boolean result=false; if (action==MotionEvent.ACTION_DOWN) { for (OverlayItem item : items) { Point p=new Point(0,0); map.getProjection().toPixels(item.getPoint(), p); if (hitTest(item, marker, x-p.x, y-p.y)) { result=true; inDrag=item; items.remove(inDrag); populate(); xDragTouchOffset=0; yDragTouchOffset=0; setDragImagePosition(p.x, p.y); dragImage.setVisibility(View.VISIBLE); xDragTouchOffset=x-p.x; yDragTouchOffset=y-p.y; break; } } } else if (action==MotionEvent.ACTION_MOVE && inDrag!=null) { setDragImagePosition(x, y); result=true; } else if (action==MotionEvent.ACTION_UP && inDrag!=null) { dragImage.setVisibility(View.GONE); GeoPoint pt=map.getProjection().fromPixels(x-xDragTouchOffset, y-yDragTouchOffset); OverlayItem toDrop=new OverlayItem(pt, inDrag.getTitle(), inDrag.getSnippet()); Toast.makeText(MapMarkerActivity.this, pt.getLatitudeE6()+" "+pt.getLongitudeE6(), Toast.LENGTH_SHORT).show(); items.add(toDrop); populate(); inDrag=null; result=true; } return(result || super.onTouchEvent(event, mapView)); } private void setDragImagePosition(int x, int y) { RelativeLayout.LayoutParams lp= (RelativeLayout.LayoutParams)dragImage.getLayoutParams(); lp.setMargins(x-xDragImageOffset-xDragTouchOffset, y-yDragImageOffset-yDragTouchOffset, 0, 0); dragImage.setLayoutParams(lp); } } }
3.) Compile and build the project.
4.) Move the marker shown on the map with the help of mouse for results shown below.
Output
发表评论
-
Spark 连接 MongoDB
2018-03-07 09:55 3349Spark 连接 Mongodb 官方地址:https://w ... -
解决android4.0系统中菜单(Menu)添加Icon无效问题
2016-02-16 16:23 1000android actionbar menu 显示icon默认 ... -
ListView 中嵌套GridView listview item 不能点击问题
2015-03-12 23:28 2106在ListView的item中有GridView,抢占焦点的情 ... -
android 手机传感器
2014-02-18 14:31 1493List<Sensor> sensors = th ... -
android regex utils
2013-12-31 22:43 0public class RegexUtils { pub ... -
Proguard on MacOSX
2013-10-26 23:33 1223[proguard] Error: Can't read [/ ... -
仿iphone actionsheet
2013-09-11 18:03 2507public class ActionSheet implem ... -
android 自定义progressbar style
2013-09-05 11:22 2728<layer-list xmlns:android=&q ... -
android ADT 17 can not find aapt when build with maven
2013-05-20 23:37 2275更新android adt 版本17之后,程序不能build了 ... -
在maven android 工程中使用高德地图
2013-04-11 21:35 4527由于程序中使用地图,最终选择了高德地图。但是高德地图中需要使用 ... -
android 代码proguard
2013-03-17 13:22 3210大家都知道,java 代码很容易被反编译,同样android ... -
Struts 标签实现时间下来选择
2012-09-13 11:58 1383<select id="min" ... -
Web browser hacks, Css hacks - ie, firefox, chrome, safri, Opera
2013-04-11 21:35 1144CSS hacks take advantage of bro ... -
Handlebars 的使用
2012-03-31 01:12 33710web 开发中,js 解析JSON 是经常的事情。非常繁琐。h ... -
使用CSS实现间隔线|(竖线)
2012-04-13 16:40 2189是不是考虑用这个? <a href="#&qu ... -
android 程序 发布加密
2011-12-01 13:37 3269大家都知道,现在java程序很容易就让别人反编译,andori ... -
<转>android 圆角效果
2011-11-30 13:31 1663最近做一个效果,要一个上边两个角为圆角,下面两个角为直角的四边 ... -
Java 文本文件和二进制文件的读取(转)
2010-07-20 11:58 12820一,文本文件的读取 1,FileInputStream:按字 ... -
java(Web)中相对路径,绝对路径问题总结
2010-04-08 18:35 11081.基本概念的理解 绝对路径:绝对路径就是你的主页上的文 ... -
java关闭系统程序
2010-01-27 13:33 1957import java.io.IOException; ...
相关推荐
该项目是一款基于freeRTOS操作系统和STM32F103x微控制器的手机远程控制浴室温度系统设计源码,共包含1087个文件,包括580个C语言源文件、269个头文件、45个汇编源文件、36个数据文件、36个目标文件、35个编译规则文件、28个包含文件、27个文本文件、6个源文件、3个归档文件。此系统通过手机远程实现对浴室温度的有效控制,适用于智能浴室环境管理。
labview程序代码参考学习使用,希望对你有所帮助。
labview程序代码参考学习使用,希望对你有所帮助。
labview程序代码参考学习使用,希望对你有所帮助。
labview程序代码参考学习使用,希望对你有所帮助。