gpt4 book ai didi

android - 如何在谷歌地图上搜索存储在我的数据库中的医生地址附近?

转载 作者:行者123 更新时间:2023-11-30 04:28:59 26 4
gpt4 key购买 nike

我正在开发一个显示的应用程序用户的当前位置也显示医生在谷歌地图上就在他附近。我开发了一个可以找到任何位置的演示应用程序并在上面放一个标记,但我不知道该怎么做通过存储在数据库中的地址查找附近。

 **My XML File:**

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:layout_width="fill_parent"
android:id="@+id/location"
android:layout_height="wrap_content"
android:text="White House" />
<Button
android:id="@+id/geocodeBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Find Location" />
</LinearLayout>
<com.google.android.maps.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="320px"
android:clickable="true"
android:apiKey=Z1oyeAgSpj5vGQVD6ADrUI2622o7yfJVJ3vEOA"

/>

</RelativeLayout>

**Manifest File:**

<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="pkg.Map"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />


<application
android:icon="@drawable/icon"
android:label="@string/app_name">
<uses-library
android:name="com.google.android.maps">
</uses-library>
<activity
android:name="pkg.GeoCoderWithMarkers.GeoCoder"
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>
<uses-permission
android:name="android.permission.INTERNET"/>
<uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION"/>
</manifest>

和 Java 文件:

package pkg.GeoCoderWithMarkers;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import pkg.Map.R;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.location.Address;
import android.location.Geocoder;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;
import com.google.android.maps.OverlayItem;

public class GeoCoder extends MapActivity {
private MapController mapController;
private MapView mapView;
GeoPoint p,p1;
private MyLocationOverlay me=null;
private LocationManager locationManager;
private Geocoder geocoder = null;
int lat;
int lng;

//** Called when the activity is first created. *//*
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView)findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);

GeoPoint pt = new GeoPoint((int)(5.34079*1000000),
(int)(100.28241*1000000));
mapView.getController().setZoom(10);
mapView.setStreetView(true);
mapView.getController().setCenter(pt);
Button geoBtn =(Button)findViewById(R.id.geocodeBtn);
geocoder = new Geocoder(this);
final Drawable marker=getResources().getDrawable
(R.drawable.pushpin_blue);
int markerWidth = marker.getIntrinsicWidth();
int markerHeight = marker.getIntrinsicHeight();
marker.setBounds(0, markerHeight, markerWidth, 0);



MyItemizedOverlay myItemizedOverlay =
new MyItemizedOverlay(marker);
mapView.getOverlays().add(myItemizedOverlay);

GeoPoint myPoint1 = new GeoPoint(lat,
(int)(100.28241*1000000));
myItemizedOverlay.addItem(myPoint1,
"myPoint1", "myPoint1");
GeoPoint myPoint2 = new GeoPoint
(50*1000000, 50*1000000);
myItemizedOverlay.addItem
(myPoint2, "myPoint2", "myPoint2");


geoBtn.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
try {
EditText loc =
(EditText)findViewById(R.id.location);

String locationName = loc.getText().toString();
List<Address> addressList =
geocoder.getFromLocationName
(locationName, 5);
if(addressList!=null && addressList.size()>0)
{
int lat = (int)(addressList.get(0).
getLatitude()*1000000);
int lng = (int)(addressList.get(0).
getLongitude()*1000000);
GeoPoint pt = new GeoPoint(lat,lng);
mapView.getController().setZoom(17);
mapView.getController().setCenter(pt);

MyItemizedOverlay myItemizedOverlay =
new MyItemizedOverlay(marker);
mapView.getOverlays().add(myItemizedOverlay);

GeoPoint myPoint1 = new GeoPoint(lat, lng);
myItemizedOverlay.addItem
(myPoint1, "myPoint1", "myPoint1");
// GeoPoint myPoint2 = new GeoPoint
(50*1000000, 50*1000000);
// myItemizedOverlay.addItem
(myPoint2, "myPoint2", "myPoint2");
}
} catch (IOException e) {
e.printStackTrace();
}
}});



}
@Override
protected boolean isRouteDisplayed() {
return false;
}


}
class MyItemizedOverlay extends
ItemizedOverlay<OverlayItem>{

private ArrayList<OverlayItem>
overlayItemList = new ArrayList<OverlayItem>();

public MyItemizedOverlay(Drawable marker) {
super(boundCenterBottom(marker));
// TODO Auto-generated constructor stub

populate();
}



public void addItem(GeoPoint p,
String title, String snippet){
OverlayItem newItem =
new OverlayItem(p, title, snippet);
overlayItemList.add(newItem);
populate();
}

@Override
protected OverlayItem createItem(int i) {
// TODO Auto-generated method stub
return overlayItemList.get(i);
}

@Override
public int size() {
// TODO Auto-generated method stub
return overlayItemList.size();
}

@Override
public void draw(Canvas canvas,
MapView mapView, boolean shadow) {
// TODO Auto-generated method stub
super.draw(canvas, mapView, shadow);
//boundCenterBottom(marker);
}

}

最佳答案

Location 类为您提供了一个非常好的方法:distanceTo(GeoPoint)。因此,只需使用此方法遍历医生的 GeoPoints。

关于android - 如何在谷歌地图上搜索存储在我的数据库中的医生地址附近?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8047463/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com