我想知道是否只应用一些标准算法就可以编写一个比较两个的短函数,std::map<string, string>如果所有键值(但是有些)都为真,则返回true.
例如,这两个地图应该被评估为相等
map<string,string> m1, m2;
m1["A"]="1";
m2["A"]="1";
m1["B"]="2";
m2["B"]="2";
m1["X"]="30";
m2["X"]="340";
m1["Y"]="53";
m2["Y"]="0";
Run Code Online (Sandbox Code Playgroud)
假设两个映射具有相同的大小,并且除了由键"X"和键"Y"存储的值之外,它们的所有元素必须成对比较.第一次尝试将是一个非常低效的双嵌套for循环.我相信可以实现更好的解决方案.
这是我的代码.我想添加自己的自定义标注视图而不是iOS默认值.我知道只有左侧标注和右侧标注视图,但我需要添加一个带有我自己的背景和标签的视图工具提示类型.
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
MKAnnotationView *userAnnotationView = nil;
if ([annotation isKindOfClass:MKUserLocation.class])
{
userAnnotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"UserLocation"];
if (userAnnotationView == nil) {
userAnnotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"UserLocation"];
}
else
userAnnotationView.annotation = annotation;
userAnnotationView.enabled = YES;
userAnnotationView.canShowCallout = YES;
userAnnotationView.image = [UIImage imageNamed:@"map_pin.png"];
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0,0,141,108)];
view.backgroundColor = [UIColor clearColor];
UIImageView *imgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"toltip.png"]];
[view addSubview:imgView];
userAnnotationView.leftCalloutAccessoryView = view;
return userAnnotationView;
}
}
Run Code Online (Sandbox Code Playgroud)

我有一个属性文件,其中值的顺序很重要.我希望能够遍历属性文件并根据原始文件的顺序输出值.
但是,由于属性文件是后备的,如果我错了,请更正我,不保持插入顺序的Map,迭代器以错误的顺序返回值.
这是我正在使用的代码
Enumeration names = propfile.propertyNames();
while (names.hasMoreElements()) {
String name = (String) names.nextElement();
//do stuff
}
Run Code Online (Sandbox Code Playgroud)
无论如何,除了编写我自己的自定义文件解析器之外,是否还要恢复属性?
在我的项目中,我想将地图的中心移动到新的坐标.这是我对地图的代码
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(0, 0),
zoom: 4,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
mapOptions);
}
function moveToLocation(lat, lng){
var center = new google.maps.LatLng(lat, lng);
var map = document.getElementById("map_canvas");
map.panTo(center);
}
Run Code Online (Sandbox Code Playgroud)
moveToLocation函数会被调用,但地图不会重新居中.知道我错过了什么吗?
我在哪里可以得到国家的SVG空白地图及其状态?
我在这里看到了美国,但我找不到其他国家(特别是亚洲) http://commons.wikimedia.org/wiki/File:USA_Counties_with_FIPS_and_names.svg
我有以下代码:
map: function (events) {
var arrayOfLatLngs = [];
var _this = this;
// setup a marker group
var markers = L.markerClusterGroup();
events.forEach(function (event) {
// setup the bounds
arrayOfLatLngs.push(event.location);
// create the marker
var marker = L.marker([event.location.lat, event.location.lng]);
marker.bindPopup(View(event));
// add marker
markers.addLayer(marker);
});
// add the group to the map
// for more see https://github.com/Leaflet/Leaflet.markercluster
this.map.addLayer(markers);
var bounds = new L.LatLngBounds(arrayOfLatLngs);
this.map.fitBounds(bounds);
this.map.invalidateSize();
}
Run Code Online (Sandbox Code Playgroud)
我最初调用此函数,它将添加所有events标记和群集的地图.
在某些其他事件中传递的泡沫点,地图将放大到新事件,但旧的事件仍然在地图上.
我尝试了this.map.removeLayer(markers);一些其他的东西,但我不能让旧的标记消失
有任何想法吗?
我刚刚开始从Android谷歌地图收到nullpointerexception,我无法弄清楚是什么导致它.目前仅在运行android 4.1的HTC Desire 500(z4u)设备上报告.任何建议或想法将不胜感激.
编辑:
所以我已经掌握了一个出错的设备(HTC Desire,Android 4.1.2,HTC SDK API 5.26).正如我在追踪中所怀疑的那样纯粹是内部错误.以下没有帮助:
堆栈跟踪如下所示:
java.lang.RuntimeException: Unable to resume activity {dk.mobikom.android/dk.mobikom.android.activities.ContactDetailActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3036)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3077)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2373)
at android.app.ActivityThread.access$600(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1330)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5536)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1074)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:841)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.google.maps.api.android.lib6.gmm6.m.ad.a(Unknown Source)
at com.google.maps.api.android.lib6.gmm6.c.h.a(Unknown Source)
at com.google.maps.api.android.lib6.gmm6.c.y.a(Unknown Source)
at com.google.maps.api.android.lib6.e.bd.a(Unknown Source)
at com.google.maps.api.android.lib6.e.ev.a(Unknown Source)
at com.google.maps.api.android.lib6.e.z.a(Unknown Source)
at com.google.maps.api.android.lib6.e.y.a(Unknown Source)
at com.google.android.gms.maps.internal.u.onTransact(SourceFile:107)
at android.os.Binder.transact(Binder.java:326) …Run Code Online (Sandbox Code Playgroud) 我试图找出确定我是否在地图循环的最后一次迭代中的最佳方法,以便执行以下操作:
for (iter = someMap.begin(); iter != someMap.end(); ++iter) {
bool last_iteration;
// do something for all iterations
if (!last_iteration) {
// do something for all but the last iteration
}
}
Run Code Online (Sandbox Code Playgroud)
似乎有几种方法可以做到这一点:随机访问迭代器,distance函数等.规范方法是什么?
编辑:没有地图的随机访问迭代器!
我正在尝试创建一个美国的等值区域地图,其默认颜色从灰色变为白色.
我有48个状态中的18个的记录,并且代码用于按值着色,但对于那些我没有记录的状态,状态是灰色的.我希望他们是白人.
如何更改颜色?
library(maps)
library(plyr)
library(ggplot2)
records1<-read.csv('E:/My Documents/records_by_state.csv')
records<-data.frame(state=tolower(rownames(records1)), records1)
head(records)
all_states<-map_data("state")
head(all_states)
record_map<-merge(all_states, records, by.x="region", by.y="state.name")
record_map<-arrange(record_map, group, order)
head(record_map)
p<- ggplot()
p<- p + geom_polygon(data=record_map, aes(x=long, y=lat, group=group, fill=record_map$Records), colour="black"
)+ scale_fill_continuous(low="thistle2", high="darkred", guide="colorbar")
P1 <- p + theme_bw() +labs(fill= "Records by State"
, title= "By State", x="", y="")
P1 + scale_y_continuous(breaks=c()) + scale_x_continuous(breaks=c()) + theme(panel.border= element_blank())
Run Code Online (Sandbox Code Playgroud) 我需要在嵌入地图上放置几个由坐标指定的标记.我知道如何为一个标记做这个,但不知道多个.
<iframe width="100%" height="100%" frameborder="0" scrolling="no" marginheight="0" marginwidth="0"
src="https://www.google.com/maps/ms?msid=204293175747830583907.0005022420ef3bca6a816&msa=0&ie=UTF8&t=m&ll=40.79042,-73.945541&spn=0.462677,1.056747&output=embed"></iframe>
Run Code Online (Sandbox Code Playgroud) maps ×10
c++ ×2
google-maps ×2
javascript ×2
stl ×2
android ×1
choropleth ×1
comparison ×1
ggplot2 ×1
html ×1
iphone ×1
iterator ×1
java ×1
leaflet ×1
properties ×1
r ×1
std ×1
svg ×1