Reputation: 337
I changed my code like below;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try
{
setContentView(R.layout.harita);
}
catch (Exception e)
{
e.printStackTrace();
}
boolean kontrol = true;
Bundle bundle = getIntent().getExtras();
String enlem = "";
if(bundle.getString("enlem") != null)
{
enlem = bundle.getString("enlem");
}
else
{
kontrol = false;
}
String boylam = "";
if(bundle.getString("boylam") != null)
{
boylam = bundle.getString("boylam");
}
else
{
kontrol = false;
}
String baslik = "";
if(bundle.getString("baslik") != null)
{
baslik = bundle.getString("baslik");
}
else
{
kontrol = false;
}
if (kontrol == true) {
GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(R.id.haritaFragment)).getMap();
LatLng position = new LatLng(Double.parseDouble(enlem),Double.parseDouble(boylam));
map.setMyLocationEnabled(true);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(position, 13));
map.addMarker(new MarkerOptions().title(baslik).snippet("Baslik").position(position));
}
}
and my layout;
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/haritaFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
I also add this code to my Manifest.xml;
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
And it's value is like that in strings.xml;
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="google_play_services_version">4030500</integer>
</resources>
I changed my codes. And now i get an error like "Binary XML file line #2: Error inflating class fragment" on setContentView try catch block.
Upvotes: 0
Views: 3021
Reputation: 26
Possible problems:
You might need to encapsulate your fragment.
Your API level should be over 8
You should add the library from the Project->Properties->Android
If you're running the Map Demo in the same workspace, I'd recommend to remove it.
This problem seem not to related to device but try test on device not emulator
Upvotes: 1
Reputation: 22183
Use this layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
</LinearLayout>
Upvotes: 0