1

所以首先我检查了是否存在 Goecoder 服务......然后我使用这个服务并检查 getFromLocationName 的结果,然后我指出它添加到我的叠加层并显示它......但由于某种原因,它不显示任何内容。

 private  void convert_Points() throws IOException {

    // initialization of overlays
    mapOverlays = mapV.getOverlays();
    drawable = this.getResources().getDrawable(R.drawable.pin);
    itemizedoverlay = new ItemizedOverlay(drawable);

    // check if getFromLocationName is present or not
    if (!Geocoder.isPresent()){
        Toast.makeText(getBaseContext(),"Sorry! Geocoder service not Present.",     Toast.LENGTH_LONG).show();
    }


    else{

    // make OverlayItem by creating a GeoPoint that defines our map coordinates
    Geocoder geocoder = new Geocoder(this);
    List<Address> geoResults = geocoder.getFromLocationName("Empire State  Building", 5,-44.00, 111.00, -12.0, 155.0);
    Address location = geoResults.get(0);
    location.getLatitude();
    location.getLongitude();

String s=Double.toString(geoResults.get(0).getLatitude());
         Toast.makeText(getBaseContext(),s, Toast.LENGTH_LONG).show();




        GeoPoint point= new GeoPoint( (int) (location.getLatitude() * 1E6), (int) (location.getLongitude() * 1E6));


        OverlayItem overlayitem = new OverlayItem(point, "", "");
    //  add this OverlayItem to a collection in the ItemizedOverlay

        itemizedoverlay.addOverlay(overlayitem);
        mapOverlays.add(itemizedoverlay);

    } 

}

4

0 回答 0