XML file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.kets"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission android:name="com.example.kets.permission.MAPS_RECEIVE"
android:protectionLevel="signature"></permission>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<uses-permission android:name="com.example.kets.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.kets.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyAiRUNy8pqAE17_eLk96PwZlc45KHokiyw"/>
<activity android:name="map"></activity>
</application>
</manifest>
JAVA CLASS
try{
URL url = new URL(b.getString("flag"));
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
bmImg = BitmapFactory.decodeStream(is);
}
catch(Exception e){
e.printStackTrace();
}
android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
SupportMapFragment mapFragment = (SupportMapFragment) fragmentManager
.findFragmentById(R.id.map);
map = mapFragment.getMap();
map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
map.setMyLocationEnabled(true);
map.setOnMarkerClickListener(this);
map.setOnInfoWindowClickListener(this);
map.addMarker(new MarkerOptions()
.snippet(""+b.getString("vic"))
.position(new LatLng(Double.parseDouble(b.getString("lat")), Double.parseDouble(b.getString("long"))))
.title(""+b.getString("name")))
.setIcon(BitmapDescriptorFactory.fromBitmap(bmImg));
CameraPosition cp = new CameraPosition.Builder().target(new LatLng(Double.parseDouble(b.getString("lat")), Double.parseDouble(b.getString("long")))).zoom(20).build();
map.animateCamera(CameraUpdateFactory.newCameraPosition(cp));
}
@Override
public boolean onMarkerClick(Marker arg0) {
// TODO Auto-generated method stub
Toast.makeText(this, ""+arg0.getTitle(), 10).show();
return false;
}
@Override
public void onInfoWindowClick(Marker arg0) {
// TODO Auto-generated method stub
Toast.makeText(this, ""+arg0.getSnippet(), 10).show();
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.kets"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission android:name="com.example.kets.permission.MAPS_RECEIVE"
android:protectionLevel="signature"></permission>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<uses-permission android:name="com.example.kets.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.kets.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyAiRUNy8pqAE17_eLk96PwZlc45KHokiyw"/>
<activity android:name="map"></activity>
</application>
</manifest>
JAVA CLASS
try{
URL url = new URL(b.getString("flag"));
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
bmImg = BitmapFactory.decodeStream(is);
}
catch(Exception e){
e.printStackTrace();
}
android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
SupportMapFragment mapFragment = (SupportMapFragment) fragmentManager
.findFragmentById(R.id.map);
map = mapFragment.getMap();
map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
map.setMyLocationEnabled(true);
map.setOnMarkerClickListener(this);
map.setOnInfoWindowClickListener(this);
map.addMarker(new MarkerOptions()
.snippet(""+b.getString("vic"))
.position(new LatLng(Double.parseDouble(b.getString("lat")), Double.parseDouble(b.getString("long"))))
.title(""+b.getString("name")))
.setIcon(BitmapDescriptorFactory.fromBitmap(bmImg));
CameraPosition cp = new CameraPosition.Builder().target(new LatLng(Double.parseDouble(b.getString("lat")), Double.parseDouble(b.getString("long")))).zoom(20).build();
map.animateCamera(CameraUpdateFactory.newCameraPosition(cp));
}
@Override
public boolean onMarkerClick(Marker arg0) {
// TODO Auto-generated method stub
Toast.makeText(this, ""+arg0.getTitle(), 10).show();
return false;
}
@Override
public void onInfoWindowClick(Marker arg0) {
// TODO Auto-generated method stub
Toast.makeText(this, ""+arg0.getSnippet(), 10).show();
}
}
No comments:
Post a Comment