pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    1. <legend id='JtBhA'><style id='JtBhA'><dir id='JtBhA'><q id='JtBhA'></q></dir></style></legend>
    2. <tfoot id='JtBhA'></tfoot>
    3. <i id='JtBhA'><tr id='JtBhA'><dt id='JtBhA'><q id='JtBhA'><span id='JtBhA'><b id='JtBhA'><form id='JtBhA'><ins id='JtBhA'></ins><ul id='JtBhA'></ul><sub id='JtBhA'></sub></form><legend id='JtBhA'></legend><bdo id='JtBhA'><pre id='JtBhA'><center id='JtBhA'></center></pre></bdo></b><th id='JtBhA'></th></span></q></dt></tr></i><div class="v5zpjp7" id='JtBhA'><tfoot id='JtBhA'></tfoot><dl id='JtBhA'><fieldset id='JtBhA'></fieldset></dl></div>
        <bdo id='JtBhA'></bdo><ul id='JtBhA'></ul>
    4. <small id='JtBhA'></small><noframes id='JtBhA'>

        Android Google Map如何檢查gps位置是否在圓圈內

        Android Google Map how to check if the gps location is inside the circle(Android Google Map如何檢查gps位置是否在圓圈內)
        <tfoot id='aiI0z'></tfoot>
      1. <legend id='aiI0z'><style id='aiI0z'><dir id='aiI0z'><q id='aiI0z'></q></dir></style></legend>

        <small id='aiI0z'></small><noframes id='aiI0z'>

                <i id='aiI0z'><tr id='aiI0z'><dt id='aiI0z'><q id='aiI0z'><span id='aiI0z'><b id='aiI0z'><form id='aiI0z'><ins id='aiI0z'></ins><ul id='aiI0z'></ul><sub id='aiI0z'></sub></form><legend id='aiI0z'></legend><bdo id='aiI0z'><pre id='aiI0z'><center id='aiI0z'></center></pre></bdo></b><th id='aiI0z'></th></span></q></dt></tr></i><div class="5z7zhfv" id='aiI0z'><tfoot id='aiI0z'></tfoot><dl id='aiI0z'><fieldset id='aiI0z'></fieldset></dl></div>
                  <tbody id='aiI0z'></tbody>

                  <bdo id='aiI0z'></bdo><ul id='aiI0z'></ul>

                  本文介紹了Android Google Map如何檢查gps位置是否在圓圈內的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在嘗試使用用戶 gps 位置檢測用戶是否在 Marker 的半徑內.我有標記的坐標,但我不知道如何計算用戶是否在該區域內.我嘗試使用以下內容,但即使當前位置在圓圈內,我也會不斷收到外部"消息.

                  I'm trying to detect if a user is in the radius of a Marker , using the users gps location. I have the marker's coordinates, but I don't know how to calculate whether the user is in the area. I've tried to use the following, but even when the current location is inside the circle I keep getting the "outside" message.

                  public class MapaEscola extends FragmentActivity {
                  
                      private GoogleMap googleMap;
                      private Serializable escolas;
                      private ProgressDialog dialog;
                      private Circle mCircle;
                      private Marker mMarker;
                  
                  
                  
                      @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
                      @Override
                      protected void onCreate(Bundle savedInstanceState) {
                          super.onCreate(savedInstanceState);
                  
                          getActionBar().setDisplayHomeAsUpEnabled(true);
                          getActionBar().setHomeButtonEnabled(true);
                  
                          setContentView(R.layout.maps);
                  
                          // Loading map
                          initilizeMap();
                  
                          // Changing map type
                          googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
                  
                          // Showing / hiding your current location
                          googleMap.setMyLocationEnabled(true);
                  
                          // Enable / Disable zooming controls
                          googleMap.getUiSettings().setZoomControlsEnabled(true);
                  
                          // Enable / Disable my location button
                          googleMap.getUiSettings().setMyLocationButtonEnabled(true);
                  
                          // Enable / Disable Compass icon
                          googleMap.getUiSettings().setCompassEnabled(true);
                  
                          // Enable / Disable Rotate gesture
                          googleMap.getUiSettings().setRotateGesturesEnabled(true);
                  
                          // Enable / Disable zooming functionality
                          googleMap.getUiSettings().setZoomGesturesEnabled(true);
                  
                          Bundle extra = getIntent().getBundleExtra("extra");
                          ArrayList<Escolas> objects = (ArrayList<Escolas>) extra.getSerializable("array");
                  
                  
                          try {
                  
                              for(int i = 0; i < objects.size(); i ++) {
                                  System.out.println(" escolas " + objects.get(i).getLatitude() + " " + objects.get(i).getLongitude());
                  
                                  float latitude = objects.get(i).getLatitude();
                                  float longitude = objects.get(i).getLongitude();
                  
                                  googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-23.316281, -51.155528), 15));
                  
                                  MarkerOptions options = new MarkerOptions();
                  
                                  // Setting the position of the marker
                  
                                  options.position(new LatLng(latitude, longitude));
                  
                                  googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
                  
                                  LatLng latLng = new LatLng(latitude, longitude);
                                  drawMarkerWithCircle(latLng);
                  
                  
                                  googleMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() {
                                      @Override
                                      public void onMyLocationChange(Location location) {
                                          float[] distance = new float[2];
                  
                                          Location.distanceBetween( mMarker.getPosition().latitude, mMarker.getPosition().longitude,
                                                  mCircle.getCenter().latitude, mCircle.getCenter().longitude, distance);
                  
                                          if( distance[0] > (mCircle.getRadius() / 2)  ){
                                              Toast.makeText(getBaseContext(), "Outside", Toast.LENGTH_LONG).show();
                                          } else {
                                              Toast.makeText(getBaseContext(), "Inside", Toast.LENGTH_LONG).show();
                                          }
                  
                                      }
                                  });
                  
                  
                  
                  
                              }
                  
                  
                  
                          } catch (Exception e) {
                              e.printStackTrace();
                          }
                      }
                  
                  
                      private void drawMarkerWithCircle(LatLng position){
                          double radiusInMeters = 500.0;
                          int strokeColor = 0xffff0000; //red outline
                          int shadeColor = 0x44ff0000; //opaque red fill
                  
                          CircleOptions circleOptions = new CircleOptions().center(position).radius(radiusInMeters).fillColor(shadeColor).strokeColor(strokeColor).strokeWidth(8);
                          mCircle = googleMap.addCircle(circleOptions);
                  
                          MarkerOptions markerOptions = new MarkerOptions().position(position);
                          mMarker = googleMap.addMarker(markerOptions);
                      }
                  
                  
                  
                      private void initilizeMap() {
                  
                          if (googleMap == null) {
                              googleMap = ((MapFragment) getFragmentManager().findFragmentById(
                                      R.id.map)).getMap();
                  
                              // check if map is created successfully or not
                              if (googleMap == null) {
                                  Toast.makeText(getApplicationContext(),
                                          "N?o foi possível carregar o mapa", Toast.LENGTH_SHORT)
                                          .show();
                              }
                          }
                      }
                  
                      @TargetApi(Build.VERSION_CODES.HONEYCOMB)
                      @Override
                      public void onBackPressed() {
                  
                          super.onBackPressed();
                          finish();
                  
                      }
                  
                      @Override
                      public boolean onCreateOptionsMenu(Menu menu) {
                          // TODO Auto-generated method stub
                          MenuInflater inflater = getMenuInflater();
                          inflater.inflate(R.menu.menu_main, menu);
                  
                          return super.onCreateOptionsMenu(menu);
                      }
                  
                      @TargetApi(Build.VERSION_CODES.HONEYCOMB)
                      public boolean onOptionsItemSelected(MenuItem item) {
                  
                  
                          switch (item.getItemId()) {
                  
                              case android.R.id.home:
                                  super.onBackPressed();
                                  finish();
                  
                                  return true;
                  
                  
                          }
                  
                          return true;
                  
                      }
                  
                      @Override
                      protected void onResume() {
                          super.onResume();
                          initilizeMap();
                      }
                  
                  
                  }
                  

                  推薦答案

                  我剛剛運行了更新的代碼,發現主要問題是什么.

                  I just ran the updated code and figured out what the main problem is.

                  您應該使用 Location 傳遞給 onMyLocationChange() 回調,以便它使用您當前的位置來判斷設備是否在圓圈內:

                  You should be using the Location passed into the onMyLocationChange() callback, so that it uses your current location to tell if the device is within the circle or not:

                  googleMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() {
                                  @Override
                                  public void onMyLocationChange(Location location) {
                                      float[] distance = new float[2];
                  
                                      /*
                                      Location.distanceBetween( mMarker.getPosition().latitude, mMarker.getPosition().longitude,
                                              mCircle.getCenter().latitude, mCircle.getCenter().longitude, distance);
                                              */
                  
                                      Location.distanceBetween( location.getLatitude(), location.getLongitude(),
                                              mCircle.getCenter().latitude, mCircle.getCenter().longitude, distance);
                  
                                      if( distance[0] > mCircle.getRadius() ){
                                          Toast.makeText(getBaseContext(), "Outside, distance from center: " + distance[0] + " radius: " + mCircle.getRadius(), Toast.LENGTH_LONG).show();
                                      } else {
                                          Toast.makeText(getBaseContext(), "Inside, distance from center: " + distance[0] + " radius: " + mCircle.getRadius() , Toast.LENGTH_LONG).show();
                                      }
                  
                                  }
                              });
                  

                  這是我運行的完整工作示例,它是您原始代碼的精簡版:

                  Here is the full working example that I ran, it's a pared down version of your original code:

                  public class MainActivity extends ActionBarActivity {
                  
                      private GoogleMap googleMap;
                      private Serializable escolas;
                      private ProgressDialog dialog;
                      private Circle mCircle;
                      private Marker mMarker;
                  
                  
                  
                      @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
                      @Override
                      protected void onCreate(Bundle savedInstanceState) {
                          super.onCreate(savedInstanceState);
                  
                          getSupportActionBar().setDisplayHomeAsUpEnabled(true);
                          getSupportActionBar().setHomeButtonEnabled(true);
                  
                          setContentView(R.layout.activity_main);
                  
                          // Loading map
                          initilizeMap();
                  
                          // Changing map type
                          googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
                  
                          // Showing / hiding your current location
                          googleMap.setMyLocationEnabled(true);
                  
                          // Enable / Disable zooming controls
                          googleMap.getUiSettings().setZoomControlsEnabled(true);
                  
                          // Enable / Disable my location button
                          googleMap.getUiSettings().setMyLocationButtonEnabled(true);
                  
                          // Enable / Disable Compass icon
                          googleMap.getUiSettings().setCompassEnabled(true);
                  
                          // Enable / Disable Rotate gesture
                          googleMap.getUiSettings().setRotateGesturesEnabled(true);
                  
                          // Enable / Disable zooming functionality
                          googleMap.getUiSettings().setZoomGesturesEnabled(true);
                  
                         // Bundle extra = getIntent().getBundleExtra("extra");
                          //ArrayList<Escolas> objects = (ArrayList<Escolas>) extra.getSerializable("array");
                  
                  
                          try {
                                 //test outside
                                 double mLatitude = 37.77657;
                                 double mLongitude = -122.417506;
                  
                  
                                  //test inside
                                  //double mLatitude = 37.7795516;
                                  //double mLongitude = -122.39292;
                  
                  
                                  googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(mLatitude, mLongitude), 15));
                  
                                  MarkerOptions options = new MarkerOptions();
                  
                                  // Setting the position of the marker
                  
                                  options.position(new LatLng(mLatitude, mLongitude));
                  
                                  //googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
                  
                                  LatLng latLng = new LatLng(mLatitude, mLongitude);
                                  drawMarkerWithCircle(latLng);
                  
                  
                                  googleMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() {
                                      @Override
                                      public void onMyLocationChange(Location location) {
                                          float[] distance = new float[2];
                  
                                          /*
                                          Location.distanceBetween( mMarker.getPosition().latitude, mMarker.getPosition().longitude,
                                                  mCircle.getCenter().latitude, mCircle.getCenter().longitude, distance);
                                                  */
                  
                                          Location.distanceBetween( location.getLatitude(), location.getLongitude(),
                                                  mCircle.getCenter().latitude, mCircle.getCenter().longitude, distance);
                  
                                          if( distance[0] > mCircle.getRadius()  ){
                                              Toast.makeText(getBaseContext(), "Outside, distance from center: " + distance[0] + " radius: " + mCircle.getRadius(), Toast.LENGTH_LONG).show();
                                          } else {
                                              Toast.makeText(getBaseContext(), "Inside, distance from center: " + distance[0] + " radius: " + mCircle.getRadius() , Toast.LENGTH_LONG).show();
                                          }
                  
                                      }
                                  });
                  
                  
                  
                  
                          } catch (Exception e) {
                              e.printStackTrace();
                          }
                      }
                  
                  
                      private void drawMarkerWithCircle(LatLng position){
                          double radiusInMeters = 500.0;
                          int strokeColor = 0xffff0000; //red outline
                          int shadeColor = 0x44ff0000; //opaque red fill
                  
                          CircleOptions circleOptions = new CircleOptions().center(position).radius(radiusInMeters).fillColor(shadeColor).strokeColor(strokeColor).strokeWidth(8);
                          mCircle = googleMap.addCircle(circleOptions);
                  
                          MarkerOptions markerOptions = new MarkerOptions().position(position);
                          mMarker = googleMap.addMarker(markerOptions);
                      }
                  
                  
                  
                      private void initilizeMap() {
                  
                          if (googleMap == null) {
                              googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(
                                      R.id.map)).getMap();
                  
                              // check if map is created successfully or not
                              if (googleMap == null) {
                                  Toast.makeText(getApplicationContext(),
                                          "N?o foi possível carregar o mapa", Toast.LENGTH_SHORT)
                                          .show();
                              }
                          }
                      }
                  
                      @TargetApi(Build.VERSION_CODES.HONEYCOMB)
                      @Override
                      public void onBackPressed() {
                  
                          super.onBackPressed();
                          finish();
                  
                      }
                  
                      @Override
                      public boolean onCreateOptionsMenu(Menu menu) {
                          // TODO Auto-generated method stub
                          MenuInflater inflater = getMenuInflater();
                          inflater.inflate(R.menu.menu_main, menu);
                  
                          return super.onCreateOptionsMenu(menu);
                      }
                  
                      @TargetApi(Build.VERSION_CODES.HONEYCOMB)
                      public boolean onOptionsItemSelected(MenuItem item) {
                  
                  
                          switch (item.getItemId()) {
                  
                              case android.R.id.home:
                                  super.onBackPressed();
                                  finish();
                  
                                  return true;
                  
                  
                          }
                  
                          return true;
                  
                      }
                  
                      @Override
                      protected void onResume() {
                          super.onResume();
                          initilizeMap();
                      }
                  
                  
                  }
                  

                  圈內結果:

                  圈外結果:

                  這篇關于Android Google Map如何檢查gps位置是否在圓圈內的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Help calculating X and Y from Latitude and Longitude in iPhone(幫助從 iPhone 中的緯度和經度計算 X 和 Y)
                  Get user#39;s current location using GPS(使用 GPS 獲取用戶的當前位置)
                  IllegalArgumentException thrown by requestLocationUpdate()(requestLocationUpdate() 拋出的 IllegalArgumentException)
                  How reliable is LocationManager#39;s getLastKnownLocation and how often is it updated?(LocationManager 的 getLastKnownLocation 有多可靠,多久更新一次?)
                  How to detect Location Provider ? GPS or Network Provider(如何檢測位置提供者?GPS 或網絡提供商)
                  Get current location during app launch(在應用啟動期間獲取當前位置)

                    <bdo id='YBUDr'></bdo><ul id='YBUDr'></ul>

                    <small id='YBUDr'></small><noframes id='YBUDr'>

                        1. <tfoot id='YBUDr'></tfoot>
                        2. <legend id='YBUDr'><style id='YBUDr'><dir id='YBUDr'><q id='YBUDr'></q></dir></style></legend>
                            <i id='YBUDr'><tr id='YBUDr'><dt id='YBUDr'><q id='YBUDr'><span id='YBUDr'><b id='YBUDr'><form id='YBUDr'><ins id='YBUDr'></ins><ul id='YBUDr'></ul><sub id='YBUDr'></sub></form><legend id='YBUDr'></legend><bdo id='YBUDr'><pre id='YBUDr'><center id='YBUDr'></center></pre></bdo></b><th id='YBUDr'></th></span></q></dt></tr></i><div class="5ffvrzx" id='YBUDr'><tfoot id='YBUDr'></tfoot><dl id='YBUDr'><fieldset id='YBUDr'></fieldset></dl></div>
                              <tbody id='YBUDr'></tbody>

                            主站蜘蛛池模板: 【北京写字楼出租_写字楼租赁_办公室出租网/出售】-远行地产官网 | IP检测-检测您的IP质量 | 江门流水线|江门工作台|江门市伟涛行工业设备有限公司 | 咖啡加盟-咖啡店加盟-咖啡西餐厅加盟-塞纳左岸咖啡西餐厅官网 | 天津仓储物流-天津电商云仓-天津云仓一件代发-博程云仓官网 | 作文导航网_作文之家_满分作文_优秀作文_作文大全_作文素材_最新作文分享发布平台 | 木材烘干机,木炭烘干机,纸管/佛香烘干设备-河南蓝天机械制造有限公司 | 上海网站建设-上海网站制作-上海网站设计-上海做网站公司-咏熠软件 | 北京软件开发_软件开发公司_北京软件公司-北京宜天信达软件开发公司 | 电力测功机,电涡流测功机,磁粉制动器,南通远辰曳引机测试台 | 昆山PCB加工_SMT贴片_PCB抄板_线路板焊接加工-昆山腾宸电子科技有限公司 | 渗透仪-直剪仪-三轴仪|苏州昱创百科 | 酒瓶_酒杯_玻璃瓶生产厂家_徐州明政玻璃制品有限公司 | 艺术漆十大品牌_艺术涂料加盟代理_蒙太奇艺术涂料厂家品牌|艺术漆|微水泥|硅藻泥|乳胶漆 | arch电源_SINPRO_开关电源_模块电源_医疗电源-东佑源 | 钢托盘,铁托盘,钢制托盘,镀锌托盘,饲料托盘,钢托盘制造商-南京飞天金属13260753852 | 脉冲布袋除尘器_除尘布袋-泊头市净化除尘设备生产厂家 | 酒水灌装机-白酒灌装机-酒精果酒酱油醋灌装设备_青州惠联灌装机械 | 流程管理|流程管理软件|企业流程管理|微宏科技-AlphaFlow_流程管理系统软件服务商 | 济南货架定做_仓储货架生产厂_重型货架厂_仓库货架批发_济南启力仓储设备有限公司 | 医学动画公司-制作3d医学动画视频-医疗医学演示动画制作-医学三维动画制作公司 | 圈酒招商网【jiushuitv.com】_酒水招商_代理_加盟平台 | NM-02立式吸污机_ZHCS-02软轴刷_二合一吸刷软轴刷-厦门地坤科技有限公司 | 质构仪_鱼糜弹性仪-上海腾拔仪器科技有限公司 | 金属波纹补偿器厂家_不锈钢膨胀节价格_非金属伸缩节定制-庆达补偿器 | 云南标线|昆明划线|道路标线|交通标线-就选云南云路施工公司-云南云路科技有限公司 | 茅茅虫AI论文写作助手-免费AIGC论文查重_写毕业论文降重 | 全自动包衣机-无菌分装隔离器-浙江迦南科技股份有限公司 | 橡胶粉碎机_橡胶磨粉机_轮胎粉碎机_轮胎磨粉机-河南鼎聚重工机械制造有限公司 | 政府回应:200块在义乌小巷能买到爱情吗?——揭秘打工族省钱约会的生存智慧 | 玻璃瓶厂家_酱菜瓶厂家_饮料瓶厂家_酒瓶厂家_玻璃杯厂家_徐州东明玻璃制品有限公司 | 破碎机锤头_合金耐磨锤头_郑州宇耐机械工程技术有限公司 | 磁力轮,磁力联轴器,磁齿轮,钕铁硼磁铁-北京磁运达厂家 | 广西绿桂涂料--承接隔热涂料、隔音涂料、真石漆、多彩仿石漆等涂料工程双包施工 | 济南玻璃安装_济南玻璃门_济南感应门_济南玻璃隔断_济南玻璃门维修_济南镜片安装_济南肯德基门_济南高隔间-济南凯轩鹏宇玻璃有限公司 | 山东锐智科电检测仪器有限公司_超声波测厚仪,涂层测厚仪,里氏硬度计,电火花检漏仪,地下管线探测仪 | 出国劳务公司_正规派遣公司[严海] | 烘干设备-热泵烘干机_广东雄贵能源设备有限公司 | 美国PARKER齿轮泵,美国PARKER柱塞泵,美国PARKER叶片泵,美国PARKER电磁阀,美国PARKER比例阀-上海维特锐实业发展有限公司二部 | 废旧物资回收公司_广州废旧设备回收_报废设备物资回收-益美工厂设备回收公司 | 网站优化公司_SEO优化_北京关键词百度快速排名-智恒博网络 |