久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    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="qwawimqqmiuu" 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="qwawimqqmiuu" 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="qwawimqqmiuu" id='YBUDr'><tfoot id='YBUDr'></tfoot><dl id='YBUDr'><fieldset id='YBUDr'></fieldset></dl></div>
                              <tbody id='YBUDr'></tbody>

                            主站蜘蛛池模板: 国产免费一区二区 | 中文字幕久久久 | 亚洲人人舔人人 | 黑人巨大精品欧美一区二区免费 | 久久久www成人免费精品张筱雨 | 欧美一区二区在线播放 | 日韩视频在线播放 | 精品欧美一区二区在线观看视频 | 成人二区 | 免费成人av网站 | 国产精品日韩 | 中文一区二区 | 国产精品明星裸体写真集 | 久久黄色网 | 第四色影音先锋 | 亚洲精品在线看 | 日韩成人免费视频 | 激情国产视频 | 91免费看片| 亚洲中国字幕 | 亚洲在线免费 | 日韩免费在线观看视频 | 99福利视频 | 成人av影院 | 欧美一区二区在线观看 | 色婷婷综合久久久中字幕精品久久 | 日韩在线中文 | 成人国产综合 | 国产在线精品一区二区三区 | 亚洲精品久久久久久宅男 | 99精品国产一区二区三区 | 日韩免费视频一区二区 | 在线一级片 | 欧美视频二区 | 韩国精品一区二区三区 | 99久久精品免费 | 黄色免费网站在线看 | 九九伊人sl水蜜桃色推荐 | 在线区 | 欧美综合一区二区 | 午夜视频一区 |