Широта и долгота фиксированного местоположения (13.060422000000000000,80.249583000000030000). если мое устройство находится в 20 метрах от этого места, оно должно показывать сообщение, подобное вам в этом районе. если выходите, это должно показать, что вы уходите с места. На данный момент я создал карту и получаю местоположение и отображение пользователя. Но я не знаю, как это сделать. Пожалуйста, помогите мне сделать это. Мой код MainActivity.javaКак вызывать сообщение, когда пользователь попадает в определенную область в googlemaps
public class MainActivity extends Activity implements LocationListener{
// static final LatLng TutorialsPoint = new LatLng(13.060422000000000000,
// 80.249583000000030000);
private GoogleMap googleMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager()
.findFragmentById(R.id.map)).getMap();
}
//googleMap.setMyLocationEnabled(true);
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = service.getBestProvider(criteria, false);
Location location = service.getLastKnownLocation(provider);
LatLng userLocation = new LatLng(location.getLatitude(),
location.getLongitude());
googleMap.addMarker(new MarkerOptions().position(userLocation)
.title("Adaptavant Technologies"));
googleMap.moveCamera(CameraUpdateFactory.newLatLng(userLocation));
googleMap.animateCamera(CameraUpdateFactory.zoomTo(15));
CircleOptions options=new CircleOptions().center(userLocation).radius(20).fillColor(0x400099FF).strokeColor(Color.TRANSPARENT).strokeWidth(2);
googleMap.addCircle(options);
} catch (Exception e) {
Log.e("simon", "Error : " + e.getMessage());
e.printStackTrace();
}
}
@Override
public void onLocationChanged(Location arg0) {
Toast.makeText(getApplicationContext(), "You are moving", Toast.LENGTH_SHORT).show();
}
}
и activity_main.xml
<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="${relativePackage}.${activityClass}" >
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.simon.learning.googlemaptesting"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<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-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name=".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>
</application>
</manifest>
так скажите, пожалуйста, как это сделать ??? Заранее спасибо
Спасибо за вас понижающим голос, но, пожалуйста, дайте мне некоторые идеи –
Google слово «Geofence». –