Mental health and HIV risk behavior have been studied with ecological momentary assessment (EMA), but this approach has not been combined with tracking of activity space (where people go and what they encounter there) in people with HIV and their social relations, who may be HIV+ or HIV−. Activity space represents a modifiable risk or protective factor for behavior related to health status and quality of life, in both clinical and nonclinical populations. We conducted an observational study with 286 participants (243 HIV+ and 43 HIV−), roughly matched for socioeconomic status and neighborhood of residence via three waves of snowball sampling. Each participant carried a smartphone for up to 4 weeks, making 5 randomly prompted entries and 1 end-of-day entry each day, plus self-initiated event-contingent entries for sexual activity and drug use. Responses to randomly prompted items provided subjective evaluations of the safety of the participant’s current social and physical environment (the place they were and the people they were with). GPS-based location tracking—coupled with publicly available statistic indicating neighborhood-level physical disorder and socioeconomic disadvantage—provided an indicator of each participant’s exposure to objective psychosocial hazard. We examined possible relationships of these objective and subjective environmental exposures with risky sexual and intravenous drug-use behavior, knowledge and utilization of antiretroviral treatment and prophylaxis, and momentary mental health (mood and stress, which relate to risky behavior and overall well-being). We found that both risky behavior and mental health were more related to participants’ subjective evaluations of their activity space than to objective measures of neighborhood-level disorder, suggesting that, even within an objectively hazardous neighborhood, people who find a niche they perceive as socially and physically safe may engage in less risky behavior and have better well-being.Trial registration Clinicaltrials.gov Identifier NCT01571752.