2014-04-11 4 views
5

मैं मानचित्र दृश्य में स्थान प्रदर्शित करना चाहता हूं & मानचित्र का आकार 200X200 होना चाहिए। मैंने नक्शादृश्य में मानचित्र लोड करने का प्रयास किया लेकिन यह दिशा सूचक 2 पर 3 बार अपने सही सही मानचित्र को प्रदर्शित करने के बाद ठीक से प्रदर्शित नहीं हो रहा है लेकिन आगे बढ़ रहा है।एंड्रॉइड में Google मानचित्र, छोटे आकार के मानचित्र दृश्य में प्रदर्शित

map

लेकिन जब मैं बदले बिना नक्शा प्रदर्शित करने के लिए स्क्रीन की पूरी आकार का उपयोग किसी भी कोड यह correctly.How लोड हो रहा है मैं छोटे दृश्य iin ही प्रदर्शित कर सकते हैं?

नक्शा code-

static GoogleMap map; 
private MapView mapView; 
MapsInitializer.initialize(getApplicationContext()); 

     switch (GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext())) 
     { 
     case ConnectionResult.SUCCESS: 
      //Toast.makeText(getActivity(), "SUCCESS", Toast.LENGTH_SHORT).show(); 
      mapView = (MapView)findViewById(R.id.map); 
      mapView.onCreate(savedInstanceState); 
      // Gets to GoogleMap from the MapView and does initialization stuff 
      if(mapView!=null) 
      { 
       map = mapView.getMap(); 
       map.getUiSettings().setMyLocationButtonEnabled(false); 
       map.setMyLocationEnabled(true); 
       CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(location, 10); 
       map.animateCamera(cameraUpdate); 
       map.setMapType(GoogleMap.MAP_TYPE_NORMAL); 
      } 
      break; 
     case ConnectionResult.SERVICE_MISSING: 
      //Toast.makeText(getActivity(), "SERVICE MISSING", Toast.LENGTH_SHORT).show(); 
      break; 
     case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED: 
      //Toast.makeText(getActivity(), "UPDATE REQUIRED", Toast.LENGTH_SHORT).show(); 
      break; 
     default: Toast.makeText(getApplicationContext(), GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext()), Toast.LENGTH_SHORT).show(); 
     } 

     CameraPosition cameraPosition = new CameraPosition.Builder() 
     .target(location).zoom(10).bearing(0) // Sets the orientation of the camera to east 
     .tilt(70) // Sets the tilt of the camera to 30 degrees 
     .build(); // Creates a CameraPosition from the builder 
     map.setBuildingsEnabled(true); 
     map.setMyLocationEnabled(true); 
     map.setMapType(GoogleMap.MAP_TYPE_NORMAL); 
     map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); 

समाधान - टुकड़ा का उपयोग किया -

map_screen.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <fragment 
     android:id="@+id/mapfragment" 
     android:layout_width="wrap_content" 
     android:layout_height="200dp" 
     android:layout_alignParentTop="true" 
     android:layout_gravity="center_horizontal" 
     class="com.google.android.gms.maps.SupportMapFragment" /> 

    <TextView 
     android:id="@+id/reg_office_title" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/mapfragment" 
     android:layout_gravity="center_horizontal" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="10dp" 
     android:layout_marginTop="5dp" 
     android:gravity="center" 
     android:text="@string/tata_auto" 
     android:textColor="@color/tatablue" 
     android:textSize="18sp" /> 

</RelativeLayout> 

जावा कोड -

public class MapFragment extends Fragment { 

    private View view; 

    public GoogleMap map; 
    private Location location; 
    private LatLng mAddress1; 
    public static boolean inMap=false; 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     view= inflater.inflate(R.layout.contact_map, container, false); 
     setMapView(); 
     return view; 
    } 

    private void setMapView(){ 
     CurrentLocation mCurrentLoc=new CurrentLocation(getActivity()); 
     location = CurrentLocation.locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); 
     if (location != null) { 
      mCurrentLoc.onLocationChanged(location); 
     } else { 
      mCurrentLoc.onLocationChanged(location); 
     } 

     //class="com.google.android.gms.maps.SupportMapFragment" 

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


     CameraPosition cameraPosition = new CameraPosition.Builder() 
     .target(mAddress1).zoom(8).bearing(0) // Sets the orientation of the camera to east 
     .tilt(30) // Sets the tilt of the camera to 30 degrees 
     .build(); // Creates a CameraPosition from the builder 
     map.setBuildingsEnabled(true); 
     map.setMyLocationEnabled(true); 
     map.setMapType(GoogleMap.MAP_TYPE_NORMAL); 
     map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); 


    } 
} 

mAddress1 आपके स्थान का अक्षांश और देशांतर है।

+0

आपको समाधान मिला है? –

+0

@LazyCoder मैंने समाधान जोड़ा है। इसे चेक करें –

+0

अपना समाधान प्रदर्शित नहीं करता –

उत्तर

5

मैं नीचे दिए गए कोड का परीक्षण किया और वहाँ आकार के नक्शे के साथ कोई समस्या नहीं है 200dp एक्स 200dp

लेआउट:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#FFFFFF" 
    android:orientation="vertical"> 

    <fragment 
     android:id="@+id/map" 
     class="com.google.android.gms.maps.SupportMapFragment" 
     android:layout_width="200dp" 
     android:layout_height="200dp" /> 

</LinearLayout> 

टुकड़ा:

public class LocationFragment extends Fragment 
{ 
    GoogleMap googleMap; 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
    { 
     View v = inflater.inflate(R.layout.fragment_location, container, false); 

     googleMap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap(); 

     MapsInitializer.initialize(getActivity().getApplicationContext()); 

     googleMap.addMarker(new MarkerOptions() 
       .position(new LatLng(38.7222524, -9.139336599999979)) 
       .title("MyLocation") 
       .icon(BitmapDescriptorFactory 
         .fromResource(R.drawable.ic_mobileedge_navpoint))); 

     // Move the camera instantly with a zoom of 15. 
     googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(38.7222524, -9.139336599999979), 15)); 

     // Zoom in, animating the camera. 
     googleMap.animateCamera(CameraUpdateFactory.zoomTo(12), 1000, null); 

     return v; 
    } 
} 
2

मुझे लगता है कि आप कर रहे हैं MapFragment के बजाय MapView का उपयोग करना। Google मानचित्र V2 में, पुराना MapView क्लास com.google.android.maps.MapView अप्रचलित है। तो आप अपने जावा कोड और एक्सएमएल लेआउट में सही MapView दोनों का उपयोग जो

import com.google.android.gms.maps.MapView; 

और

<com.google.android.gms.maps.MapView 
    android:id="@+id/map_view" 
    android:layout_width="your_width" 
    android:layout_height="your_height" /> 

यह भी सुनिश्चित करें कि आप AndroidManifest.xml में सभी आवश्यक परिवर्तन किए हैं बनाने होना चाहिए यह सुनिश्चित कर लें, जिसमें शामिल मानचित्र V2 as described here के लिए API_KEY को परिभाषित करना।

इसके अलावा, वहाँ एक प्रमुख बात यह है कि आप अगर आप एक MapFragment के स्थान पर MapView उपयोग कर रहे हैं क्या करना है, तो आप सिर्फ गतिविधि रहने वाले की तरह की इसी ओवरराइड अंदर स्पष्ट MapView के ओवरराइड कार्यों कॉल करने के लिए है,

public class YourMapActivity extends Activity { 

    MapView mMapView; 
    GoogleMap mMap; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     /* Your OnCreate with Map Initialization */ 

     mMapView = (MapView) findViewById(R.id.map_view); 
     mMapView.onCreate(Bundle.EMPTY); 

     mMap = mMapView.getMap(); 
     MapsInitializer.initialize(this); 
    } 

    @Override 
    protected void onResume() { 
     mMapView.onResume(); 
     super.onResume(); 
    } 

    @Override 
    protected void onPause() { 
     mMapView.onPause(); 
     super.onPause(); 
    } 

    @Override 
    protected void onDestroy() { 
     mMapView.onDestroy(); 
     super.onDestroy(); 
    } 

    @Override 
    public void onLowMemory() { 
     mMapView.onLowMemory(); 
     super.onLowMemory(); 
    } 
} 

यह आपके एसिटीविटी में कस्टम आकार के मानचित्र दृश्य को लोड करने के लिए पर्याप्त होना चाहिए। आप अपनी आवश्यकता के अनुरूप बनाने के लिए निम्न कार्यों का भी उपयोग कर सकते हैं।

mMapView.setClickable(false); 

mMap.getUiSettings().setMyLocationButtonnabled(false); 
mMap.getUiSettings().setZoomControlsEnabled(false); 
mMap.getUiSettings().setCompassEnabled(false); 
mMap.getUiSettings().setZoomGesturesEnabled(false); 
mMap.getUiSettings().setScrollGesturesEnabled(false); 
mMap.setMyLocationEnabled(true); 
+0

नीचे वोट? क्यूं कर? मुझे यकीन है कि जिस व्यक्ति ने मतदान किया है, वह इसे आजमाया नहीं है। कम से कम, एक टिप्पणी छोड़ दी जानी चाहिए थी। – gnuanu

संबंधित मुद्दे