- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这里是执行 2 点(origin, current location){geoPoint, "current Location"}
到 Destination.{geoPoint1, "Desti Location2"之间的道路路径或路线路径的代码}
。它对我来说工作得很好。
我的问题是如何确定当前位置与搜索位置之间的道路。这里我是按钮搜索位置的 onClick
,它显示得很完美,但是我在引用--> {当前位置(scrgeoPoint)到搜索位置(destgeopointsearch)}<之间的路线图中出现错误
.
有人有什么想法吗?
//search button onclick
mapLocationBtn = (Button) findViewById(R.id.locationbutton);
mapLocationBtn.setVisibility(View.INVISIBLE);
mapLocationBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String usrLoc = autoCompletetextView.getText().toString();
Geocoder gc = new Geocoder(PlacesMapActivity.this);
try {
addr=gc.getFromLocationName(usrLoc, 3);//maximum 2 results
if(addr.size()>0){
address=addr.get(0);//get the first result
convertLongi=address.getLongitude();
convertLati=address.getLatitude();
geopointsearch = new GeoPoint((int)(convertLati * 1E6), (int)(convertLongi * 1E6));
// Map geopointsearch overlay item
itemizedOverlay2 = new AddItemizedOverlay(drawable_client, PlacesMapActivity.this);
overlayitem = new OverlayItem(geopointsearch, "Your Location3", "R u Searching For me!");
itemizedOverlay2.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay2);
itemizedOverlay2.populateNow();
mc.animateTo(geopointsearch);
// mc.zoomIn();
}
} catch (IOException e) {
e.printStackTrace();
}
}
});
// Map overlay item
itemizedOverlay = new AddItemizedOverlay(drawable_user, this);
overlayitem = new OverlayItem(geoPoint, "Your Location","That is you!");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
itemizedOverlay.populateNow();
// Map client overlay item
itemizedOverlay1 = new AddItemizedOverlay(drawable_client, this);
overlayitem1 = new OverlayItem(geoPoint1, "Your Location2", "I am ur client!");
itemizedOverlay1.addOverlay(overlayitem1);
mapOverlays.add(itemizedOverlay1);
itemizedOverlay1.populateNow();
// Map near overlay item
itemizedOverlay = new AddItemizedOverlay(drawable, this);
mc = mapView.getController();
// These values are used to get map boundary area
// The area where you can see all the markers on screen
int minLat = Integer.MAX_VALUE;
int minLong = Integer.MAX_VALUE;
int maxLat = Integer.MIN_VALUE;
int maxLong = Integer.MIN_VALUE;
// check for null in case it is null
if (nearPlaces.results != null) {
// loop through all the places
for (Place place : nearPlaces.results) {
latitude = place.geometry.location.lat; // latitude
longitude = place.geometry.location.lng; // longitude
// Geopoint to place on map
geoPoin = new GeoPoint((int) (latitude * 1E6),
(int) (longitude * 1E6));
// Map overlay item
overlayitem = new OverlayItem(geoPoin, place.name,
place.vicinity);
itemizedOverlay.addOverlay(overlayitem);
// calculating map boundary area
minLat = (int) Math.min( geoPoin.getLatitudeE6(), minLat );
minLong = (int) Math.min( geoPoin.getLongitudeE6(), minLong);
maxLat = (int) Math.max( geoPoin.getLatitudeE6(), maxLat );
maxLong = (int) Math.max( geoPoin.getLongitudeE6(), maxLong );
}
mapOverlays.add(itemizedOverlay);
// showing all overlay items
itemizedOverlay.populateNow();
}
DrawPath(geoPoint, geoPoint1, geopointsearch, Color.GREEN, mapView);
// Adjusting the zoom level so that you can see all the markers on map
mapView.getController().zoomToSpan(Math.abs( minLat - maxLat ), Math.abs( minLong - maxLong ));
// Showing the center of the map
mc.animateTo(new GeoPoint((maxLat + minLat)/2, (maxLong + minLong)/2 ));
mc.animateTo(geoPoint1);
mapView.postInvalidate();
}
private void DrawPath(GeoPoint scrgeoPoint, GeoPoint destgeoPoint, GeoPoint destgeopointsearch, int green, MapView mMapView) {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(makeUrl(scrgeoPoint, destgeoPoint, destgeopointsearch));
HttpResponse response;
try {
response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
InputStream is = null;
is = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
sb.append(reader.readLine() + "\n");
String line = "0";
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
reader.close();
String result = sb.toString();
JSONObject jsonObject = new JSONObject(result);
JSONArray routeArray = jsonObject.getJSONArray("routes");
JSONObject routes = routeArray.getJSONObject(0);
// calculate the distance between 2 point
JSONArray legs = routes.getJSONArray("legs");
Log.d("JSON","legs: "+legs.toString());
JSONObject steps = legs.getJSONObject(0);
Log.d("JSON","steps: "+steps.toString());
JSONObject distance = steps.getJSONObject("distance");
Log.d("JSON","distance: "+distance.toString());
String sDistance = distance.getString("text");
int iDistance = distance.getInt("value");
distextView = (TextView) findViewById(R.id.distextView);
distextView.setText(distance.getString("text"));
JSONObject overviewPolylines = routes.getJSONObject("overview_polyline");
String encodedString = overviewPolylines.getString("points");
List<GeoPoint> pointToDraw = decodePoly(encodedString);
mMapView.getOverlays().add(new MyOverLay(pointToDraw));
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
private List<GeoPoint> decodePoly(String encoded) {
List<GeoPoint> poly = new ArrayList<GeoPoint>();
int index = 0, len = encoded.length();
int lat = 0, lng = 0;
while (index < len) {
int b, shift = 0, result = 0;
do {
b = encoded.charAt(index++) - 63;
result |= (b & 0x1f) << shift;
shift += 5;
} while (b >= 0x20);
int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
lat += dlat;
shift = 0;
result = 0;
do {
b = encoded.charAt(index++) - 63;
result |= (b & 0x1f) << shift;
shift += 5;
} while (b >= 0x20);
int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
lng += dlng;
GeoPoint p = new GeoPoint((int) (((double) lat / 1E5) * 1E6),
(int) (((double) lng / 1E5) * 1E6));
poly.add(p);
}
return poly;
}
private String makeUrl(GeoPoint scrgeoPoint, GeoPoint destgeoPoint, GeoPoint destgeopointsearch) {
StringBuilder urlString = new StringBuilder();
//Origin
urlString.append("http://maps.googleapis.com/maps/api/directions/json");
urlString.append("?origin=");// from
urlString.append(Double.toString((double) scrgeoPoint.getLatitudeE6() / 1.0E6));
urlString.append(",");
urlString.append(Double.toString((double) scrgeoPoint.getLongitudeE6() / 1.0E6));
//Destination
urlString.append("&destination=");// to
urlString.append(Double.toString((double) destgeoPoint.getLatitudeE6() / 1.0E6));
urlString.append(",");
urlString.append(Double.toString((double) destgeoPoint.getLongitudeE6() / 1.0E6));
//search location
urlString.append("&destination=");// to
urlString.append(Double.toString((double) destgeopointsearch.getLatitudeE6() / 1.0E6));
urlString.append(",");
urlString.append(Double.toString((double) destgeopointsearch.getLongitudeE6() / 1.0E6));
urlString.append("&mode=walking&sensor=true");
Log.d("xxx", "URL=" + urlString.toString());
return urlString.toString();
}
最佳答案
据我了解,您需要保存您的位置和目的地,然后向 Google 询问方向,可能是这样的:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=20.344,34.34&daddr=20.5666,45.345"));
startActivity(intent);
(摘自 this 帖子。)
然后你需要在许多点之间画一条线/路径(从Google收到),以便在不穿过建筑物和角落的情况下实现路径。也许这段代码会对您有所启发:
private List<Overlay> mapOverlays;
private Projection projection;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
linearLayout = (LinearLayout) findViewById(R.id.zoomview);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
mapOverlays = mapView.getOverlays();
projection = mapView.getProjection();
mapOverlays.add(new MyOverlay());
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
class MyOverlay extends Overlay{
public MyOverlay(){
}
public void draw(Canvas canvas, MapView mapv, boolean shadow){
super.draw(canvas, mapv, shadow);
Paint mPaint = new Paint();
mPaint.setDither(true);
mPaint.setColor(Color.RED);
mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setStrokeWidth(2);
GeoPoint gP1 = new GeoPoint(19240000,-99120000);
GeoPoint gP2 = new GeoPoint(37423157, -122085008);
Point p1 = new Point();
Point p2 = new Point();
Path path = new Path();
projection.toPixels(gP1, p1);
projection.toPixels(gP2, p2);
path.moveTo(p2.x, p2.y);
path.lineTo(p1.x,p1.y);
canvas.drawPath(path, mPaint);
}
(摘自 this 帖子。)
关于java - 当前位置和搜索位置之间的道路/路线图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12264710/
我正在制作一个基于网格的游戏。 在这个游戏中,您可以放置建筑物、墙壁和道路。 当某些东西被放置在网格中时,我将单元格 ID 设置为该对象 ID。到目前为止一切顺利,一切正常。 当我需要时,我的问题
我想创建一个交互式 map ,其中道路等的样式为我想要的颜色。现在,我了解了 Mapbox,但这不是我们想要使用的,因为最终它会因为费用而花费我们很多钱。 我一直在互联网上寻找替代方案。我发现了很多拼
我正在尝试用 Java 制作一个正则表达式,它可以粗略地用于匹配某些街道名称。我想这样做,以便给定以下字符串: Then someone decided to go to the high stree
尝试用颜色“标记”一个区域并在该区域放置一个数字: 我在这里说明了它: 数字是静态的,不会改变。 区域标记假设会改变颜色。并且区域标记假设使用周围的街道/道路包围该区域(不仅仅是简单的圆形图) 我会尝
我需要能够使用 V2 或 V3(最好是 3)创建在某种意义上忽略建筑物的路径。 我什至试图创建一个 kml 文件来自己绘制所有路径,然后找到一些方法根据需要打开/关闭它们。 例如。用户想从 A 点到
我在 http://www.41latitude.com/post/1268734799/google-styled-maps 上找到了一个代码片段: [ { featureType: "
我正在使用 Roads Google API 传递一个位置列表,我想根据这些点在最有可能由汽车行驶的道路上画线。 有些地方出了问题,因为有些点没有被线穿过,而且这些线不仅仅使用道路,有些点通过直线穿过
我们如何使用切换按钮在 Mapbox gl js 中突出显示(更改颜色)道路、人行道或自行车道? 最佳答案 您可以使用setPaintProperty更改图层的填充颜色,就像在官方 Mapbox 示例
我正在尝试在道路上绘制一条路径并遵循一些给定的点。我正在使用 Google Directions API 来遵循道路。我在道路上放置了一些标记并将这些点与折线连接起来。我需要遵循红线但是它跟随并绘制蓝
我是一名优秀的程序员,十分优秀!