2013-06-19 80 views
0

我想使用谷歌地圖V2加載地圖使用GPS或互聯網,我可以使用只是互聯網。谷歌地圖加載地圖使用互聯網或GPS

當我在我的應用程序連接到互聯網

,地圖加載成功,但如果我只是使用的GPS地圖上沒有顯示,即使我已經在我的手機和我的應用程序activiate的GPS。

這是我的代碼,第一次讓我的位置,然後我加載MAPP

setContentView(R.layout.google_map_layout); 
     locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); 
     boolean enabled = locationManager 
       .isProviderEnabled(LocationManager.GPS_PROVIDER); 
     if (!enabled) { 
      Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); 
      startActivity(intent); 
     } else { 

      Criteria criteria = new Criteria(); 
      provider = locationManager.getBestProvider(criteria, false); 
      Location location = locationManager.getLastKnownLocation(provider); 
      if (location != null) { 
       Toast.makeText(RestaurantsNearBy.this, 
         location.getLatitude() + "", Toast.LENGTH_LONG).show(); 
       LatLng currentLocation = new LatLng(location.getLatitude(), 
         location.getLongitude()); 
       new getRestaurantNearBy().execute(currentLocation.latitude, 
         currentLocation.longitude); 

       map = ((SupportMapFragment) getSupportFragmentManager() 
         .findFragmentById(R.id.map)).getMap(); 

       map.setInfoWindowAdapter(new InfoWindowAdapter() { 

        private final View window = getLayoutInflater().inflate(
          R.layout.restaurant_marker, null); 

        @Override 
        public View getInfoWindow(Marker marker) { 
         return null; 
        } 

        @Override 
        public View getInfoContents(Marker marker) { 
         TextView tv_title = ((TextView) window 
           .findViewById(R.id.tv_title)); 
         TextView tv_description = ((TextView) window 
           .findViewById(R.id.tv_description)); 
         ImageView iv_image = ((ImageView) window 
           .findViewById(R.id.iv_image)); 
         AddressMap oneAddres = markersMap.get(marker); 
         tv_title.setText(oneAddres.getRestaurant().getName()); 
         tv_description.setText(oneAddres.getDescription()); 
         Restaurant r = markersMap.get(marker).getRestaurant(); 
         if (Restaurant.getRestaurant(r.getID()) != null) { 
          if (Restaurant.getRestaurant(r.getID()).getImage() != null) { 
           iv_image.setImageBitmap(Restaurant 
             .getRestaurant(r.getID()).getImage()); 
          } else { 
           try { 
            iv_image.setImageBitmap(r 
              .getImageFromWebService()); 
           } catch (Exception e) { 
            iv_image.setImageResource(R.drawable.unknown); 
           } 
          } 
         } else { 
          iv_image.setImageBitmap(r.getImageFromWebService()); 
         } 
         return window; 
        } 
       }); 

       map.setOnInfoWindowClickListener(new OnInfoWindowClickListener() { 

        @Override 
        public void onInfoWindowClick(Marker marker) { 
         final AddressMap oneAddress = markersMap.get(marker); 
         AlertDialog alertDialog3 = new AlertDialog.Builder(
           RestaurantsNearBy.this).create(); 
         alertDialog3.setTitle("Order !"); 
         alertDialog3 
           .setMessage("Do you want to order from the restaurant " 
             + oneAddress.getRestaurant().getName()); 
         alertDialog3.setIcon(R.drawable.more_information); 
         alertDialog3.setButton("Yes", 
           new DialogInterface.OnClickListener() { 
            @Override 
            public void onClick(DialogInterface dialog, 
              int which) { 
             Basket.setRestaurant(oneAddress 
               .getRestaurant()); 
             dialog.dismiss(); 
             Intent addAddressIntent = new Intent(
               RestaurantsNearBy.this, 
               OrderMeal.class); 
             startActivity(addAddressIntent); 
            } 

           }); 
         alertDialog3.setButton2("No", 
           new DialogInterface.OnClickListener() { 

            @Override 
            public void onClick(DialogInterface dialog, 
              int which) { 
             dialog.dismiss(); 
            } 
           }); 
         alertDialog3.show(); 

        } 
       }); 

       // Move the camera instantly to hamburg with a zoom of 15. 
       map.moveCamera(CameraUpdateFactory.newLatLngZoom(
         currentLocation, 15)); 

       // Zoom in, animating the camera. 
       map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null); 
       Log.d("Provider ", provider + " has been selected."); 
       onLocationChanged(location); 
      } else { 
       Toast.makeText(RestaurantsNearBy.this, "Sorry we couldn't define your location", 
         Toast.LENGTH_SHORT).show(); 
      } 
     } 

回答

1

你應該用適當的標籤,谷歌地圖可以在平臺的負載被發現,你有一個關於Android的版本問題,所以至少增加Android的標籤。

在問題中:當您第一次加載地圖時,Google地圖需要有效的Internet連接。 V2在你的SD卡上做了一些體面的緩存(有時也有點過分),讓你稍後檢查已經加載的離線地圖,但原則是:沒有活動的互聯網連接,沒有谷歌地圖。

ps:GPS不是互聯網連接。

1

默認情況下,如果你不與WiFi或移動連接連接不能正常加載地圖數據。 GPS只能讓你找到你的位置。